Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ if err := cmd.Run(context.TODO(), os.Args[1:]); err != nil {

- [ ] Audit bare `err` returns
- [ ] Two types of errors: config and parse
- [ ] Tab completion
- [x] Tab completion
- [ ] Allow variadic arguments
- [ ] Allow slice and map based flags?
34 changes: 34 additions & 0 deletions command_options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cli

import (
"context"
"fmt"
"sort"

"github.com/broothie/option"
Expand Down Expand Up @@ -91,3 +93,35 @@ func AddVersionFlag(options ...option.Option[*Flag]) option.Func[*Command] {
defaultOptions := option.NewOptions(setFlagIsVersion(true), SetFlagDefault(false))
return AddFlag(versionFlagName, "Print version.", append(defaultOptions, options...)...)
}

// EnableCompletion adds a hidden completion command to the root command
func EnableCompletion() option.Func[*Command] {
return func(command *Command) (*Command, error) {
// Only add to root commands
if command.parent != nil {
return command, nil
}

completionCmd := CompletionCommand(command)
return MountSubCmd(completionCmd).Apply(command)
}
}

// AddCompletionCommand adds a "completion" subcommand that generates shell completion scripts
func AddCompletionCommand() option.Func[*Command] {
return func(command *Command) (*Command, error) {
// Only add to root commands
if command.parent != nil {
return command, nil
}

return AddSubCmd("completion", "Generate shell completion scripts",
AddSubCmd("bash", "Generate bash completion script",
SetHandler(func(ctx context.Context) error {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude I'm seeing

Error: ./command_options.go:119:25: undefined: context

Copy link

@claude claude bot Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude finished @broothie's task —— View job


Todo List

  • Read command_options.go to analyze the compilation error
  • Fix the missing context import
  • Commit the fix to the PR branch
  • Verify the change resolves the error

Fix Applied

Fixed the compilation error!

Issue: ./command_options.go:119:25: undefined: context

Solution: Added the missing "context" import to the import block at the top of command_options.go

Changes:

  • Added "context" import on line 4
  • This resolves the undefined context error on line 119 where context.Context is used in the handler function

The fix has been committed to the PR branch: 5826091


fmt.Print(command.GenerateBashCompletion())
return nil
}),
),
).Apply(command)
}
}
Loading
Loading