selectWorkflow displays an interactive list for workflow selection with fuzzy search
(ctx context.Context, workflows []WorkflowOption)
| 169 | |
| 170 | // selectWorkflow displays an interactive list for workflow selection with fuzzy search |
| 171 | func 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 |
| 210 | func selectWorkflowNonInteractive(workflows []WorkflowOption) (*WorkflowOption, error) { |
no test coverage detected