NewListCommand creates the list command
()
| 27 | |
| 28 | // NewListCommand creates the list command |
| 29 | func NewListCommand() *cobra.Command { |
| 30 | cmd := &cobra.Command{ |
| 31 | Use: "list [pattern]", |
| 32 | Short: "List agentic workflows in the repository", |
| 33 | Long: `List all agentic workflows in a repository without checking their status. |
| 34 | |
| 35 | Displays a simplified table with workflow name, AI engine, and compilation status. |
| 36 | Unlike 'status', this command does not check GitHub workflow state or time remaining. |
| 37 | |
| 38 | The optional pattern argument filters workflows by name (case-insensitive substring match). |
| 39 | It accepts workflow IDs (basename without .md) or full filenames.`, |
| 40 | Example: ` ` + string(constants.CLIExtensionPrefix) + ` list # List all workflows in current repo |
| 41 | ` + string(constants.CLIExtensionPrefix) + ` list --repo github/gh-aw # List workflows from github/gh-aw repo |
| 42 | ` + string(constants.CLIExtensionPrefix) + ` list --repo org/repo --path workflows # List from custom path |
| 43 | ` + string(constants.CLIExtensionPrefix) + ` list --dir custom/workflows # List from custom local directory |
| 44 | ` + string(constants.CLIExtensionPrefix) + ` list ci- # List workflows with 'ci-' in name |
| 45 | ` + string(constants.CLIExtensionPrefix) + ` list --repo github/gh-aw ci- # List workflows from github/gh-aw with 'ci-' in name |
| 46 | ` + string(constants.CLIExtensionPrefix) + ` list --json # Output in JSON format |
| 47 | ` + string(constants.CLIExtensionPrefix) + ` list --label automation # List workflows with 'automation' label`, |
| 48 | RunE: func(cmd *cobra.Command, args []string) error { |
| 49 | var pattern string |
| 50 | if len(args) > 0 { |
| 51 | pattern = args[0] |
| 52 | } |
| 53 | |
| 54 | repo, _ := cmd.Flags().GetString("repo") |
| 55 | path, _ := cmd.Flags().GetString("path") |
| 56 | dir, _ := cmd.Flags().GetString("dir") |
| 57 | verbose, _ := cmd.Flags().GetBool("verbose") |
| 58 | jsonFlag, _ := cmd.Flags().GetBool("json") |
| 59 | labelFilter, _ := cmd.Flags().GetString("label") |
| 60 | |
| 61 | // --dir overrides the local workflow directory when no remote repo is specified. |
| 62 | // When --repo is set, --path is used for the remote repository path instead. |
| 63 | if dir != "" && repo == "" { |
| 64 | path = dir |
| 65 | } |
| 66 | return RunListWorkflows(repo, path, pattern, verbose, jsonFlag, labelFilter) |
| 67 | }, |
| 68 | } |
| 69 | |
| 70 | addRepoFlag(cmd) |
| 71 | addJSONFlag(cmd) |
| 72 | cmd.Flags().String("label", "", "Filter workflows by label") |
| 73 | cmd.Flags().String("path", constants.GetWorkflowDir(), "Path to workflows directory in the remote repository (used with --repo)") |
| 74 | cmd.Flags().StringP("dir", "d", "", "Workflow directory (default: $GH_AW_WORKFLOWS_DIR or .github/workflows; ignored when --repo is set)") |
| 75 | |
| 76 | // Register completions for list command |
| 77 | cmd.ValidArgsFunction = CompleteWorkflowNames |
| 78 | RegisterDirFlagCompletion(cmd, "dir") |
| 79 | |
| 80 | return cmd |
| 81 | } |
| 82 | |
| 83 | // RunListWorkflows lists workflows without checking GitHub status |
| 84 | func RunListWorkflows(repo, path, pattern string, verbose bool, jsonOutput bool, labelFilter string) error { |