# For bash source <(main.exe completion bash) source <(main.exe completion zsh) For fish main.exe completion fish | source 3. Completion Logic | Context | Suggestions | |---------|-------------| | Top-level | user , logs , config , help , version | | After user | create , delete , list , get | | Flags -- | --name , --role , --help | | Flag values (e.g., --role ) | admin , editor , viewer | | File args | local file/dir paths | | Numbers (e.g., --limit ) | no suggestion (dynamic) | 4. Code Example (using Go + cobra ) If using Cobra, built-in completion works automatically:
main.exe __complete "partial input" Returns: main.exe autocom
Outputs the completion script to stdout. User adds to their shell profile: # For bash source <(main
// Add this command cmd := &cobra.Commandpowershell]", Short: "Generate completion script", Run: func(cmd *cobra.Command, args []string) switch args[0] case "bash": cmd.Root().GenBashCompletion(os.Stdout) case "zsh": cmd.Root().GenZshCompletion(os.Stdout) // ... , User adds to their shell profile: // Add
main.exe completion <shell> Supported shells: bash , zsh , fish , powershell