Skip to content

Commit

Permalink
Merge pull request #19 from muandane/feat/cobra
Browse files Browse the repository at this point in the history
Feat/cobra
  • Loading branch information
muandane authored Nov 13, 2023
2 parents 809634c + b9bcd57 commit 1473bcc
Show file tree
Hide file tree
Showing 87 changed files with 13,047 additions and 286 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4.1.0
with:
go-version: '1.20.5'
- name: Check out code
uses: actions/checkout@v2
go-version: '1.21.4'
- name: Check out code
uses: actions/checkout@v4.1.1
- name: Test and generate coverage report
run: cd src/ && go test -coverprofile=coverage.out ./...
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v3.1.4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
file: coverage.out
14 changes: 6 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
- name: Check out code
uses: actions/[email protected]
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/[email protected]
- name: Set up Go
uses: actions/[email protected]
with:
go-version: '1.20.5'
go-version: '1.21.4'
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@v5.0.0
with:
distribution: goreleaser
version: ${{ env.GITHUB_REF_NAME }}
Expand Down
11 changes: 9 additions & 2 deletions src/.goreleaser.yml → .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
before:
hooks:
- ./scripts/completions.sh
builds:
- binary: goji
main: ./cmd
main: src/
goos:
- darwin
- linux
Expand All @@ -12,7 +15,7 @@ builds:
flags:
- -mod=vendor
ldflags:
- -s -w -X main.version={{.Version}}
- -s -w -X cmd.version={{.Version}}

release:
prerelease: auto
Expand All @@ -30,6 +33,10 @@ brews:
commit_author:
name: muandane
email: [email protected]
extra_install: |-
bash_completion.install "completions/goji.bash" => "goji"
zsh_completion.install "completions/goji.zsh" => "_goji"
fish_completion.install "completions/goji.fish"
checksum:
name_template: 'checksums.txt'
7 changes: 7 additions & 0 deletions scripts/completions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e
rm -rf completions
mkdir completions
for sh in bash zsh fish; do
go run main.go completion "$sh" >"completions/goji.$sh"
done
75 changes: 75 additions & 0 deletions src/cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

// completionCmd represents the completion command
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: fmt.Sprintf(`To load completions:
Bash:
$ source <(%[1]s completion bash)
# To load completions for each session, execute once:
# Linux:
$ %[1]s completion bash > /etc/bash_completion.d/%[1]s
# macOS:
$ %[1]s completion bash > $(brew --prefix)/etc/bash_completion.d/%[1]s
Zsh:
# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
# To load completions for each session, execute once:
$ %[1]s completion zsh > "${fpath[1]}/_%[1]s"
# You will need to start a new shell for this setup to take effect.
fish:
$ %[1]s completion fish | source
# To load completions for each session, execute once:
$ %[1]s completion fish > ~/.config/fish/completions/%[1]s.fish
PowerShell:
PS> %[1]s completion powershell | Out-String | Invoke-Expression
# To load completions for every new session, run:
PS> %[1]s completion powershell > %[1]s.ps1
# and source this file from your PowerShell profile.
`, rootCmd.Name()),
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
rootCmd.GenBashCompletion(os.Stdout)
case "zsh":
rootCmd.GenZshCompletion(os.Stdout)
case "fish":
rootCmd.GenFishCompletion(os.Stdout, true)
case "powershell":
rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
}
},
}

func init() {
rootCmd.AddCommand(completionCmd)
}
159 changes: 0 additions & 159 deletions src/cmd/goji.go

This file was deleted.

Loading

0 comments on commit 1473bcc

Please sign in to comment.