Skip to content

Commit 0775d65

Browse files
authored
fix: disallow --name flag when adding multiple workflows at once (#28195)
1 parent 1e34942 commit 0775d65

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

.changeset/patch-add-multiple-workflows.md

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/add_command.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Workflow specifications:
7373
- Local wildcard: "./*.md" or "./dir/*.md" (adds all .md files matching pattern)
7474
- Version can be tag, branch, or SHA (for remote workflows)
7575
76-
The -n flag allows you to specify a custom name for the workflow file (only applies to the first workflow when adding multiple).
76+
The -n flag allows you to specify a custom name for the workflow file (not allowed when adding multiple workflows at once).
7777
The --dir flag allows you to specify the workflow directory (default: .github/workflows).
7878
The --create-pull-request flag creates a pull request with the workflow changes.
7979
The --force flag overwrites existing workflow files.
@@ -101,6 +101,11 @@ Note: For guided interactive setup, use the 'add-wizard' command instead.`,
101101
noStopAfter, _ := cmd.Flags().GetBool("no-stop-after")
102102
stopAfter, _ := cmd.Flags().GetString("stop-after")
103103
disableSecurityScanner, _ := cmd.Flags().GetBool("disable-security-scanner")
104+
105+
if nameFlag != "" && len(workflows) > 1 {
106+
return errors.New("--name flag cannot be used when adding multiple workflows at once")
107+
}
108+
104109
if err := validateEngine(engineOverride); err != nil {
105110
return err
106111
}

pkg/cli/add_command_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,15 @@ func TestAddCommandArgs(t *testing.T) {
337337
err = cmd.Args(cmd, []string{"workflow1", "workflow2"})
338338
require.NoError(t, err, "Should not error with multiple arguments")
339339
}
340+
341+
// TestAddMultipleWorkflowsNameFlag verifies that --name is not allowed when multiple workflows are specified.
342+
func TestAddMultipleWorkflowsNameFlag(t *testing.T) {
343+
cmd := NewAddCommand(validateEngineStub)
344+
345+
// Simulate calling the command with --name and multiple workflow arguments
346+
cmd.SetArgs([]string{"workflow1", "workflow2", "--name", "custom-name"})
347+
348+
err := cmd.Execute()
349+
require.Error(t, err, "Should error when --name is used with multiple workflows")
350+
assert.Contains(t, err.Error(), "--name flag cannot be used when adding multiple workflows", "Error should mention --name restriction")
351+
}

0 commit comments

Comments
 (0)