Skip to content

Commit

Permalink
Merge pull request #18 from njhale/enhance-basic-completions
Browse files Browse the repository at this point in the history
enhance: enable shell completions
  • Loading branch information
njhale authored Feb 12, 2024
2 parents e28e7b7 + fa863df commit 41c9c9d
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit 41c9c9d

Please sign in to comment.