-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from grafana/48-fix-subcommand-flags-handling
fix subcommand flags handling
- Loading branch information
Showing
4 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
type argsKey struct{} | ||
|
||
// SetArgs set arguments for cmd command and store the args in the context. | ||
func SetArgs(cmd *cobra.Command, args []string) { | ||
ctx := cmd.Context() | ||
if ctx == nil { | ||
ctx = context.Background() | ||
} | ||
|
||
cmd.SetContext(context.WithValue(ctx, argsKey{}, args)) | ||
|
||
cmd.SetArgs(args) | ||
} | ||
|
||
func getArgs(cmd *cobra.Command) []string { | ||
ctx := cmd.Context() | ||
if ctx == nil { | ||
return nil | ||
} | ||
|
||
value := ctx.Value(argsKey{}) | ||
if value == nil { | ||
return nil | ||
} | ||
|
||
args, ok := value.([]string) | ||
if !ok { | ||
return nil | ||
} | ||
|
||
for idx := range args { | ||
if args[idx] == cmd.Name() { | ||
return args[idx+1:] | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
k6exec `v0.1.8` is here 🎉! | ||
|
||
This is an internal bugfix release. | ||
|
||
**Fix subcommand flags handling** | ||
|
||
Passing subcommand specific flags was not possible, k6exec swallowed these flags. | ||
This has been fixed. |