MCPcopy Create free account
hub / github.com/github/gh-aw / selectWorkflow

Function selectWorkflow

pkg/cli/run_interactive.go:171–207  ·  view source on GitHub ↗

selectWorkflow displays an interactive list for workflow selection with fuzzy search

(ctx context.Context, workflows []WorkflowOption)

Source from the content-addressed store, hash-verified

169
170// selectWorkflow displays an interactive list for workflow selection with fuzzy search
171func selectWorkflow(ctx context.Context, workflows []WorkflowOption) (*WorkflowOption, error) {
172 runInteractiveLog.Printf("Displaying workflow selection: %d workflows", len(workflows))
173
174 // Check if we're in a TTY environment
175 if !tty.IsStderrTerminal() {
176 return selectWorkflowNonInteractive(workflows)
177 }
178
179 // Build select options
180 options := sliceutil.Map(workflows, func(wf WorkflowOption) huh.Option[string] { return huh.NewOption(wf.Name, wf.Name) })
181
182 var selected string
183 form := huh.NewForm(
184 huh.NewGroup(
185 huh.NewSelect[string]().
186 Title("Select a workflow to run").
187 Description("↑/↓ to navigate, / to search, Enter to select").
188 Options(options...).
189 Filtering(true).
190 Height(15).
191 Value(&selected),
192 ),
193 ).WithTheme(styles.HuhTheme).WithAccessible(console.IsAccessibleMode())
194
195 if err := form.RunWithContext(ctx); err != nil {
196 return nil, fmt.Errorf("workflow selection cancelled or failed: %w", err)
197 }
198
199 // Find the selected workflow
200 for i := range workflows {
201 if workflows[i].Name == selected {
202 return &workflows[i], nil
203 }
204 }
205
206 return nil, fmt.Errorf("selected workflow not found: %s", selected)
207}
208
209// selectWorkflowNonInteractive provides a fallback for non-TTY environments
210func selectWorkflowNonInteractive(workflows []WorkflowOption) (*WorkflowOption, error) {

Callers 1

RunWorkflowInteractivelyFunction · 0.85

Calls 6

IsStderrTerminalFunction · 0.92
MapFunction · 0.92
IsAccessibleModeFunction · 0.92
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected