@@ -25,6 +25,7 @@ import (
25
25
"github.com/gptscript-ai/gptscript/pkg/types"
26
26
"github.com/gptscript-ai/gptscript/pkg/version"
27
27
"github.com/spf13/cobra"
28
+ "github.com/spf13/pflag"
28
29
"golang.org/x/term"
29
30
)
30
31
@@ -58,9 +59,44 @@ type GPTScript struct {
58
59
59
60
func New () * cobra.Command {
60
61
root := & GPTScript {}
61
- return cmd .Command (root , & Eval {
62
+ command := cmd .Command (root , & Eval {
62
63
gptscript : root ,
63
64
}, & Credential {root : root })
65
+
66
+ // Hide all the global flags for the credential subcommand.
67
+ for _ , child := range command .Commands () {
68
+ if strings .HasPrefix (child .Name (), "credential" ) {
69
+ command .PersistentFlags ().VisitAll (func (f * pflag.Flag ) {
70
+ newFlag := pflag.Flag {
71
+ Name : f .Name ,
72
+ Usage : f .Usage ,
73
+ }
74
+
75
+ if f .Name != "credential-context" { // We want to keep credential-context
76
+ child .Flags ().AddFlag (& newFlag )
77
+ child .Flags ().Lookup (newFlag .Name ).Hidden = true
78
+ }
79
+ })
80
+
81
+ for _ , grandchild := range child .Commands () {
82
+ command .PersistentFlags ().VisitAll (func (f * pflag.Flag ) {
83
+ newFlag := pflag.Flag {
84
+ Name : f .Name ,
85
+ Usage : f .Usage ,
86
+ }
87
+
88
+ if f .Name != "credential-context" {
89
+ grandchild .Flags ().AddFlag (& newFlag )
90
+ grandchild .Flags ().Lookup (newFlag .Name ).Hidden = true
91
+ }
92
+ })
93
+ }
94
+
95
+ break
96
+ }
97
+ }
98
+
99
+ return command
64
100
}
65
101
66
102
func (r * GPTScript ) NewRunContext (cmd * cobra.Command ) context.Context {
0 commit comments