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

Conversation

njhale
Copy link
Member

@njhale njhale commented Feb 12, 2024

Enable basic shell completions for bash, zsh, fish, and
powershell by exposing the completion command automatically
generated by Cobra. The command is hidden, so it doesn't show up
in the help text or completions.

$ source <(gptscript completion zsh)
$ gptscript --[tab]
 -- completions --
--assemble            -- Assemble tool to a single artifact, saved to --output ($GPTSCRIPT_ASSEMBLE)
--cache               -- Disable caching ($GPTSCRIPT_CACHE)
--cache-dir           -- Directory to store cache (default: $XDG_CACHE_HOME/gptscript) ($GPTSCRIPT_CACHE_DIR)
--debug               -- Enable debug logging ($GPTSCRIPT_DEBUG)
--dump-state          -- Dump the internal execution state to a file ($GPTSCRIPT_DUMP_STATE)
--help                -- help for gptscript
--input               -- Read input from a file ("-" for stdin) ($GPTSCRIPT_INPUT)
--list-models         -- List the models available and exit ($GPTSCRIPT_LIST_MODELS)
--list-tools          -- List built-in tools and exit ($GPTSCRIPT_LIST_TOOLS)
--listen-address      -- Server listen address ($GPTSCRIPT_LISTEN_ADDRESS)
--openai-api-key      -- OpenAI API KEY ($OPENAI_API_KEY)
--openai-api-type     -- OpenAI API Type (valid: OPEN_AI, AZURE, AZURE_AD) ($OPENAI_API_TYPE)
--openai-api-version  -- OpenAI API Version (for Azure) ($OPENAI_API_VERSION)
--openai-base-url     -- OpenAI base URL ($OPENAI_BASE_URL)
--openai-org-id       -- OpenAI organization ID ($OPENAI_ORG_ID)
--output              -- Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
--quiet               -- No output logging ($GPTSCRIPT_QUIET)
--server              -- Start server ($GPTSCRIPT_SERVER)
--sub-tool            -- Use tool of this name, not the first tool in file ($GPTSCRIPT_SUB_TOOL)
--version             -- version for gptscript

This implementation produces file path completions for ALL positional and flag args.
Support for customizing completions for individual arguments will
require new features in github.com/acorn-io/cmd and should be
addressed in a followup.

@njhale
Copy link
Member Author

njhale commented Feb 12, 2024

looks like this change is causing some issues, going to put it into draft hold off on merging until I fix it.

Enable basic shell completions for `bash`, `zsh`, `fish`, and
`powershell` by exposing the `completion` command automatically
generated by Cobra. The command is hidden, so it doesn't show up
in the help text or completions.

```zsh
$ source <(gptscript completion zsh)
$ gptscript --[tab]
 -- completions --
--assemble            -- Assemble tool to a single artifact, saved to --output ($GPTSCRIPT_ASSEMBLE)
--cache               -- Disable caching ($GPTSCRIPT_CACHE)
--cache-dir           -- Directory to store cache (default: $XDG_CACHE_HOME/gptscript) ($GPTSCRIPT_CACHE_DIR)
--debug               -- Enable debug logging ($GPTSCRIPT_DEBUG)
--dump-state          -- Dump the internal execution state to a file ($GPTSCRIPT_DUMP_STATE)
--help                -- help for gptscript
--input               -- Read input from a file ("-" for stdin) ($GPTSCRIPT_INPUT)
--list-models         -- List the models available and exit ($GPTSCRIPT_LIST_MODELS)
--list-tools          -- List built-in tools and exit ($GPTSCRIPT_LIST_TOOLS)
--listen-address      -- Server listen address ($GPTSCRIPT_LISTEN_ADDRESS)
--openai-api-key      -- OpenAI API KEY ($OPENAI_API_KEY)
--openai-api-type     -- OpenAI API Type (valid: OPEN_AI, AZURE, AZURE_AD) ($OPENAI_API_TYPE)
--openai-api-version  -- OpenAI API Version (for Azure) ($OPENAI_API_VERSION)
--openai-base-url     -- OpenAI base URL ($OPENAI_BASE_URL)
--openai-org-id       -- OpenAI organization ID ($OPENAI_ORG_ID)
--output              -- Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT)
--quiet               -- No output logging ($GPTSCRIPT_QUIET)
--server              -- Start server ($GPTSCRIPT_SERVER)
--sub-tool            -- Use tool of this name, not the first tool in file ($GPTSCRIPT_SUB_TOOL)
--version             -- version for gptscript
```

This implementation produces file path completions for ALL positional and flag args.
Support for customizing completions for individual arguments will
require new features in `github.com/acorn-io/cmd` and should be
addressed in a followup.

Signed-off-by: Nick Hale <[email protected]>
@njhale njhale force-pushed the enhance-basic-completions branch from c5a9b50 to fa863df Compare February 12, 2024 15:40
@njhale
Copy link
Member Author

njhale commented Feb 12, 2024

Okay, setting TraverseChildren = true did the trick.

@njhale njhale merged commit 41c9c9d into gptscript-ai:main Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants