Skip to content

fix: credentials: hide unneeded global flags #247

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 2 commits into from
Apr 15, 2024
Merged
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/samber/lo v1.38.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.17.1
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
Expand Down Expand Up @@ -68,7 +69,6 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
github.com/therootcompany/xz v1.0.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
Expand Down
38 changes: 37 additions & 1 deletion pkg/cli/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/gptscript-ai/gptscript/pkg/types"
"github.com/gptscript-ai/gptscript/pkg/version"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"golang.org/x/term"
)

Expand Down Expand Up @@ -58,9 +59,44 @@ type GPTScript struct {

func New() *cobra.Command {
root := &GPTScript{}
return cmd.Command(root, &Eval{
command := cmd.Command(root, &Eval{
gptscript: root,
}, &Credential{root: root})

// Hide all the global flags for the credential subcommand.
for _, child := range command.Commands() {
if strings.HasPrefix(child.Name(), "credential") {
command.PersistentFlags().VisitAll(func(f *pflag.Flag) {
newFlag := pflag.Flag{
Name: f.Name,
Usage: f.Usage,
}

if f.Name != "credential-context" { // We want to keep credential-context
child.Flags().AddFlag(&newFlag)
child.Flags().Lookup(newFlag.Name).Hidden = true
}
})

for _, grandchild := range child.Commands() {
command.PersistentFlags().VisitAll(func(f *pflag.Flag) {
newFlag := pflag.Flag{
Name: f.Name,
Usage: f.Usage,
}

if f.Name != "credential-context" {
grandchild.Flags().AddFlag(&newFlag)
grandchild.Flags().Lookup(newFlag.Name).Hidden = true
}
})
}

break
}
}

return command
}

func (r *GPTScript) NewRunContext(cmd *cobra.Command) context.Context {
Expand Down