@@ -54,19 +54,19 @@ func completeForMode(d prompt.Document, mode HelpMode) []prompt.Suggest {
5454 case HelpModeProvider :
5555 return providerSuggestions (ctx , args , word )
5656 case HelpModeShell :
57- return shellSuggestions (args , word )
57+ return shellSuggestions (ctx , args , word )
5858 default :
59- return rootSuggestions (args , word )
59+ return rootSuggestions (ctx , args , word )
6060 }
6161}
6262
63- func rootSuggestions (args []string , word string ) []prompt.Suggest {
63+ func rootSuggestions (ctx CompletionContext , args []string , word string ) []prompt.Suggest {
6464 if len (args ) <= 1 {
65- return prompt .FilterHasPrefix (rootCommandSuggestions , word , true )
65+ return prompt .FilterHasPrefix (commandSuggestionsForContext ( ctx ) , word , true )
6666 }
6767 switch args [0 ] {
6868 case "help" :
69- return helpSuggestions (args , word )
69+ return helpSuggestions (ctx , args , word )
7070 case "use" :
7171 if len (args ) == 2 {
7272 return prompt .FilterContains (modules , word , true )
@@ -81,14 +81,11 @@ func rootSuggestions(args []string, word string) []prompt.Suggest {
8181
8282func providerSuggestions (ctx CompletionContext , args []string , word string ) []prompt.Suggest {
8383 if len (args ) <= 1 {
84- if ctx .DemoReplay {
85- return prompt .FilterHasPrefix (mockCommandSuggestions (), word , true )
86- }
87- return prompt .FilterHasPrefix (providerCommandSuggestionsData , word , true )
84+ return prompt .FilterHasPrefix (commandSuggestionsForContext (ctx ), word , true )
8885 }
8986 switch args [0 ] {
9087 case "help" :
91- return helpSuggestions (args , word )
88+ return helpSuggestions (ctx , args , word )
9289 case "use" :
9390 if len (args ) == 2 {
9491 return prompt .FilterContains (modules , word , true )
@@ -107,13 +104,13 @@ func providerSuggestions(ctx CompletionContext, args []string, word string) []pr
107104 return []prompt.Suggest {}
108105}
109106
110- func shellSuggestions (args []string , word string ) []prompt.Suggest {
107+ func shellSuggestions (ctx CompletionContext , args []string , word string ) []prompt.Suggest {
111108 if len (args ) <= 1 {
112- return prompt .FilterHasPrefix (shellCommandSuggestions , word , true )
109+ return prompt .FilterHasPrefix (commandSuggestionsForContext ( ctx ) , word , true )
113110 }
114111 switch args [0 ] {
115112 case "help" :
116- return helpSuggestions (args , word )
113+ return helpSuggestions (ctx , args , word )
117114 }
118115 return []prompt.Suggest {}
119116}
@@ -163,19 +160,20 @@ func completionArgs(d prompt.Document) []string {
163160 return args
164161}
165162
166- func helpSuggestions (args []string , word string ) []prompt.Suggest {
163+ func helpSuggestions (ctx CompletionContext , args []string , word string ) []prompt.Suggest {
167164 if len (args ) == 2 {
168- return prompt .FilterContains (helpTopicSuggestions (), word , true )
165+ return prompt .FilterContains (helpTopicSuggestions (ctx ), word , true )
169166 }
170167 if len (args ) == 3 && (args [1 ] == "payload" || args [1 ] == "metadata" ) {
171168 return prompt .FilterContains (payloadSuggestions (), word , true )
172169 }
173170 return []prompt.Suggest {}
174171}
175172
176- func helpTopicSuggestions () []prompt.Suggest {
177- suggestions := make ([]prompt.Suggest , 0 , len (helpTopicOrder ))
178- for _ , key := range helpTopicOrder {
173+ func helpTopicSuggestions (ctx CompletionContext ) []prompt.Suggest {
174+ keys := helpTopicKeysForContext (ctx )
175+ suggestions := make ([]prompt.Suggest , 0 , len (keys ))
176+ for _ , key := range keys {
179177 if topic , ok := helpTopics [key ]; ok {
180178 suggestions = append (suggestions , prompt.Suggest {
181179 Text : key ,
@@ -186,6 +184,36 @@ func helpTopicSuggestions() []prompt.Suggest {
186184 return suggestions
187185}
188186
187+ func helpTopicKeysForContext (ctx CompletionContext ) []string {
188+ keys := make ([]string , 0 , len (helpTopicOrder ))
189+ seen := make (map [string ]struct {}, len (helpTopicOrder ))
190+
191+ appendKey := func (key string ) {
192+ if _ , ok := helpTopics [key ]; ! ok {
193+ return
194+ }
195+ if _ , ok := seen [key ]; ok {
196+ return
197+ }
198+ seen [key ] = struct {}{}
199+ keys = append (keys , key )
200+ }
201+
202+ for _ , key := range commandNamesForContext (ctx .Mode , ctx .DemoReplay ) {
203+ appendKey (key )
204+ }
205+ if ctx .Mode == HelpModeProvider && ctx .DemoReplay {
206+ appendKey ("demo" )
207+ }
208+ appendKey ("payload" )
209+ appendKey ("metadata" )
210+
211+ for _ , key := range helpTopicOrder {
212+ appendKey (key )
213+ }
214+ return keys
215+ }
216+
189217func optionSuggestions (ctx CompletionContext ) []prompt.Suggest {
190218 keys := []string {utils .Payload , utils .Metadata }
191219 seen := map [string ]struct {}{
0 commit comments