Skip to content

Commit

Permalink
Disabling all arguments after foreach (#51)
Browse files Browse the repository at this point in the history
Fixes #50.
Uses `DisableFlagParsing` as per the documentation to disable the
subsequent flag parsing in the command and leaving it as arguments to
the shell command.

Added `TraverseChildren` to rootCmd to allow -v and -h to be parsed.

https://pkg.go.dev/github.com/spf13/cobra#Command

Tested on Mac OS.

I'm unable to write tests as we're not testing the flag parsing at the
moment.
  • Loading branch information
sledigabel authored Sep 8, 2021
1 parent 425dd7c commit e2183ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions cmd/foreach/foreach.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ var exec executor.Executor = executor.NewRealExecutor()

func NewForeachCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "foreach -- SHELL_COMMAND",
Short: "Run a shell command against each working copy",
Run: run,
Args: cobra.MinimumNArgs(1),
Use: "foreach -- SHELL_COMMAND",
Short: "Run a shell command against each working copy",
Run: run,
Args: cobra.MinimumNArgs(1),
DisableFlagParsing: true,
}

return cmd
Expand Down
9 changes: 5 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ var commit = "commit-dev"
var date = "date-dev"

var rootCmd = &cobra.Command{
Use: "turbolift",
Short: "Turbolift",
Long: `Mass refactoring tool for repositories in GitHub`,
Version: fmt.Sprintf("%s (%s, built %s)", version, commit, date),
Use: "turbolift",
Short: "Turbolift",
Long: `Mass refactoring tool for repositories in GitHub`,
Version: fmt.Sprintf("%s (%s, built %s)", version, commit, date),
TraverseChildren: true,
}

func init() {
Expand Down

0 comments on commit e2183ea

Please sign in to comment.