-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var completionDesc = `To load completions: | ||
Bash: | ||
$ source <(%[1]s completion bash) | ||
# To load completions for each session, execute once: | ||
$ echo "\nsource <(%[1]s completion bash)" >> ~/.bashrc | ||
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. | ||
` | ||
|
||
// completionCmd represents the completion command | ||
var completionCmd = &cobra.Command{ | ||
Use: "completion [bash|zsh]", | ||
Short: "Generate completion script", | ||
Long: fmt.Sprintf(completionDesc, rootCmd.Root().Name()), | ||
DisableFlagsInUseLine: true, | ||
ValidArgs: []string{"bash", "zsh"}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) > 0 { | ||
switch args[0] { | ||
case "bash": | ||
_ = cmd.Root().GenBashCompletion(os.Stdout) | ||
case "zsh": | ||
_ = cmd.Root().GenZshCompletion(os.Stdout) | ||
} | ||
} else { | ||
fmt.Printf(completionDesc, rootCmd.Root().Name()) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(completionCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ var recreateServiceCmd = &cobra.Command{ | |
downService() | ||
upService() | ||
}, | ||
ValidArgs: []string{"--service"}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters