NewFixCommand creates the fix command
()
| 33 | |
| 34 | // NewFixCommand creates the fix command |
| 35 | func NewFixCommand() *cobra.Command { |
| 36 | cmd := &cobra.Command{ |
| 37 | Use: "fix [workflow]...", |
| 38 | Short: "Apply automatic codemod-style fixes to agentic workflow files", |
| 39 | Long: `Apply automatic codemod-style fixes to agentic workflow files. |
| 40 | |
| 41 | This command applies a registry of codemods that automatically update deprecated fields |
| 42 | and migrate to new syntax. Codemods preserve formatting and comments as much as possible. |
| 43 | |
| 44 | Use --list-codemods to see all available codemods and their descriptions. |
| 45 | |
| 46 | If no workflows are specified, all Markdown files in .github/workflows will be processed. |
| 47 | |
| 48 | The command will: |
| 49 | 1. Scan workflow files for deprecated fields |
| 50 | 2. Apply relevant codemods to fix issues |
| 51 | 3. Report what was changed in each file |
| 52 | |
| 53 | Without --write (dry-run mode), no files are modified. With --write, the command performs |
| 54 | all steps and additionally: |
| 55 | 4. Write updated files back to disk |
| 56 | 5. Delete deprecated .github/aw/schemas/agentic-workflow.json file if it exists |
| 57 | 6. Delete old template files from previous versions if present |
| 58 | 7. Delete old workflow-specific .agent.md files from .github/agents/ if present |
| 59 | |
| 60 | ` + WorkflowIDExplanation, |
| 61 | Example: ` ` + string(constants.CLIExtensionPrefix) + ` fix # Check all workflows (dry-run) |
| 62 | ` + string(constants.CLIExtensionPrefix) + ` fix --write # Fix all workflows |
| 63 | ` + string(constants.CLIExtensionPrefix) + ` fix my-workflow # Check specific workflow |
| 64 | ` + string(constants.CLIExtensionPrefix) + ` fix my-workflow --write # Fix specific workflow |
| 65 | ` + string(constants.CLIExtensionPrefix) + ` fix --dir custom/workflows # Fix workflows in custom directory |
| 66 | ` + string(constants.CLIExtensionPrefix) + ` fix --list-codemods # List available codemods`, |
| 67 | RunE: func(cmd *cobra.Command, args []string) error { |
| 68 | listCodemods, _ := cmd.Flags().GetBool("list-codemods") |
| 69 | write, _ := cmd.Flags().GetBool("write") |
| 70 | verbose, _ := cmd.Flags().GetBool("verbose") |
| 71 | dir, _ := cmd.Flags().GetString("dir") |
| 72 | disabledCodemods, _ := cmd.Flags().GetStringSlice("disable-codemod") |
| 73 | |
| 74 | if listCodemods { |
| 75 | return listAvailableCodemods() |
| 76 | } |
| 77 | |
| 78 | return runFixCommand(args, write, verbose, dir, disabledCodemods) |
| 79 | }, |
| 80 | } |
| 81 | |
| 82 | cmd.Flags().Bool("write", false, "Write changes to files (without this flag, no changes are made)") |
| 83 | cmd.Flags().Bool("list-codemods", false, "List all available codemods and exit") |
| 84 | cmd.Flags().StringP("dir", "d", "", "Workflow directory (default: .github/workflows)") |
| 85 | cmd.Flags().StringSlice("disable-codemod", nil, "Disable specific codemod IDs during the fix step (repeatable)") |
| 86 | |
| 87 | // Register completions |
| 88 | cmd.ValidArgsFunction = CompleteWorkflowNames |
| 89 | RegisterDirFlagCompletion(cmd, "dir") |
| 90 | |
| 91 | return cmd |
| 92 | } |