Skip to content

enhance: enable shell completions #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2024
Merged
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
17 changes: 16 additions & 1 deletion pkg/cli/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,23 @@ func New() *cobra.Command {
}

func (r *GPTScript) Customize(cmd *cobra.Command) {
cmd.Use = version.ProgramName + " [flags] PROGRAM_FILE [INPUT...]"
cmd.Flags().SetInterspersed(false)
cmd.Use = version.ProgramName + " [flags] PROGRAM_FILE [INPUT...]"
cmd.Version = version.Get().String()
cmd.CompletionOptions.HiddenDefaultCmd = true
cmd.TraverseChildren = true

// Enable shell completion for the gptscript command.
// Note: The gptscript command doesn't have any subcommands, but Cobra requires that at least one is defined before
// it will generate the completion command automatically. To work around this, define a hidden no-op subcommand.
cmd.AddCommand(&cobra.Command{Hidden: true})
cmd.SetHelpCommand(&cobra.Command{Hidden: true})

// Override arg completion to prevent the hidden subcommands from masking default completion for positional args.
// Note: This should be removed if the gptscript command supports subcommands in the future.
cmd.ValidArgsFunction = func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveDefault
}
}

func (r *GPTScript) listTools(ctx context.Context) error {
Expand Down