Add documentation for completion command

This commit is contained in:
Abin Simon 2023-11-16 19:39:32 +05:30
parent 84f4400635
commit 78f2dbdccb
5 changed files with 22 additions and 5 deletions

View File

@ -149,10 +149,25 @@ func BuildCommandTree(cmd *cobra.Command) {
// harder to control it, for example skipping printing "Logging to file"
// message
func AddCompletion(cmd *cobra.Command) {
longMessage := `Generate shell completion script for Corso.
These need to be hooked into your shell to enable completions for Corso.
For bash, add the following line to your ` + "`~/.bashrc` \n" + // two spaces for markdown and \n for go
"`eval \"$(corso completion bash)\"` \n" + `
For zsh, add the following line to your ` + "`~/.zshrc` \n" +
"`eval \"$(corso completion zsh)\"` \n" + `
For fish, add the following line to your ` + "`~/.config/fish/config.fish` \n" +
"`corso completion fish | source` \n" + `
For powershell, add the following to your ` + "`$PROFILE` \n" +
"`Invoke-Expression \"$(corso completion powershell)\"`"
completion := &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: "To load completions",
Long: longMessage,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),

View File

@ -27,7 +27,7 @@ func SubcommandsRequiredWithSuggestions(cmd *cobra.Command, args []string) error
cmd.SuggestionsMinimumDistance = 2
}
// subcommand suggestions
suggestions = append(cmd.SuggestionsFor(args[0]))
suggestions = cmd.SuggestionsFor(args[0])
// subcommand alias suggestions (with distance, not exact)
for _, c := range cmd.Commands() {

View File

@ -89,7 +89,8 @@ func fatal(err error) {
// Adapted from https://github.com/spf13/cobra/blob/main/doc/md_docs.go for Corso specific formatting
func genMarkdownCorso(cmd *cobra.Command, dir string) error {
for _, c := range cmd.Commands() {
if !isAvailableCommand(c) || c.IsAdditionalHelpTopicCommand() {
if c.Use != "completion [bash|zsh|fish|powershell]" &&
(!isAvailableCommand(c) || c.IsAdditionalHelpTopicCommand()) {
continue
}

View File

@ -36,4 +36,4 @@ Below is a list of known Corso issues and limitations:
* Restoring the data into a different Group from the one it was backed up from isn't currently supported
* CLI completions cannot autocomplete multiple values for flags
* CLI completions can't autocomplete multiple values for flags

View File

@ -54,7 +54,8 @@ const sidebars = {
'cli/corso-repo-connect-filesystem',
'cli/corso-repo-maintenance',
'cli/corso-repo-update-passphrase',
'cli/corso-env']
'cli/corso-env',
'cli/corso-completion']
},
{
type: 'category',