Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/patch-add-multiple-workflows.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pkg/cli/add_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Workflow specifications:
- Local wildcard: "./*.md" or "./dir/*.md" (adds all .md files matching pattern)
- Version can be tag, branch, or SHA (for remote workflows)

The -n flag allows you to specify a custom name for the workflow file (only applies to the first workflow when adding multiple).
The -n flag allows you to specify a custom name for the workflow file (not allowed when adding multiple workflows at once).
The --dir flag allows you to specify the workflow directory (default: .github/workflows).
The --create-pull-request flag creates a pull request with the workflow changes.
The --force flag overwrites existing workflow files.
Expand Down Expand Up @@ -101,6 +101,11 @@ Note: For guided interactive setup, use the 'add-wizard' command instead.`,
noStopAfter, _ := cmd.Flags().GetBool("no-stop-after")
stopAfter, _ := cmd.Flags().GetString("stop-after")
disableSecurityScanner, _ := cmd.Flags().GetBool("disable-security-scanner")

if nameFlag != "" && len(workflows) > 1 {
return errors.New("--name flag cannot be used when adding multiple workflows at once")
}
Comment on lines +105 to +107
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation only triggers when nameFlag != "" and len(args) > 1, which still allows using --name in cases where a single argument resolves to multiple workflows (e.g., local wildcard patterns) and also allows --name="" since the value remains empty. To fully enforce “flag cannot be used when adding multiple workflows”, consider checking cmd.Flags().Changed("name") and validating against the number of resolved workflows (or pre-expanding local wildcards) rather than only len(args) and a non-empty string value.

Copilot uses AI. Check for mistakes.

if err := validateEngine(engineOverride); err != nil {
return err
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/cli/add_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,15 @@ func TestAddCommandArgs(t *testing.T) {
err = cmd.Args(cmd, []string{"workflow1", "workflow2"})
require.NoError(t, err, "Should not error with multiple arguments")
}

// TestAddMultipleWorkflowsNameFlag verifies that --name is not allowed when multiple workflows are specified.
func TestAddMultipleWorkflowsNameFlag(t *testing.T) {
cmd := NewAddCommand(validateEngineStub)

// Simulate calling the command with --name and multiple workflow arguments
cmd.SetArgs([]string{"workflow1", "workflow2", "--name", "custom-name"})

err := cmd.Execute()
require.Error(t, err, "Should error when --name is used with multiple workflows")
assert.Contains(t, err.Error(), "--name flag cannot be used when adding multiple workflows", "Error should mention --name restriction")
Comment on lines +343 to +350
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test covers the multiple-args case, but it doesn’t exercise other “multiple workflows at once” paths that the new restriction likely intends to cover, such as a single local wildcard argument that resolves to multiple workflows, or --name="" (flag present but empty). Adding tests for these cases would help prevent regressions once the validation is tightened.

Suggested change
cmd := NewAddCommand(validateEngineStub)
// Simulate calling the command with --name and multiple workflow arguments
cmd.SetArgs([]string{"workflow1", "workflow2", "--name", "custom-name"})
err := cmd.Execute()
require.Error(t, err, "Should error when --name is used with multiple workflows")
assert.Contains(t, err.Error(), "--name flag cannot be used when adding multiple workflows", "Error should mention --name restriction")
tests := []struct {
name string
args []string
}{
{
name: "non-empty name with multiple workflow arguments",
args: []string{"workflow1", "workflow2", "--name", "custom-name"},
},
{
name: "explicitly empty name with multiple workflow arguments",
args: []string{"workflow1", "workflow2", "--name="},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := NewAddCommand(validateEngineStub)
// Simulate calling the command with --name and multiple workflow arguments
cmd.SetArgs(tt.args)
err := cmd.Execute()
require.Error(t, err, "Should error when --name is used with multiple workflows")
assert.Contains(t, err.Error(), "--name flag cannot be used when adding multiple workflows", "Error should mention --name restriction")
})
}

Copilot uses AI. Check for mistakes.
}
Loading