Skip to content

Commit

Permalink
🐛 properly parse flags for commands containing -- (#4730)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Oct 14, 2024
1 parent 85010c1 commit 6c3502e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main-benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
path: ./cache
key: ${{ runner.os }}-benchmark-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-benchmark
${{ runner.os }}-benchmark-
# Run `github-action-benchmark` action
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
path: ./cache
key: ${{ runner.os }}-benchmark-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-benchmark
${{ runner.os }}-benchmark-
# Run `github-action-benchmark` action
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
Expand Down
3 changes: 3 additions & 0 deletions providers/os/resources/processes/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func (f *FlagSet) ParseCommand(cmd string) error {
n := len(args)
for i := 0; i < n; i++ {
key := args[i]
if key == "--" {
break
}
if strings.HasPrefix(key, "-") {
if i+1 < n && !strings.HasPrefix(args[i+1], "-") {
preparedArgs = append(preparedArgs, key+"="+args[i+1])
Expand Down
11 changes: 11 additions & 0 deletions providers/os/resources/processes/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ func TestFlagParser(t *testing.T) {
"node-labels": "eks.amazonaws.com/sourceLaunchTemplateVersion=1,alpha.eksctl.io/nodegroup-name=ng-1c08897f,alpha.eksctl.io/cluster-name=cluster1,eks.amazonaws.com/nodegroup-image=ami-0656dd273bd6e9a2f,eks.amazonaws.com/capacityType=ON_DEMAND,eks.amazonaws.com/nodegroup=ng-1c08897f,eks.amazonaws.com/sourceLaunchTemplateId=lt-079b3a8f38d6aa1a9",
},
},
{
cmd: "tini -- fleetcontroller gitjob --gitjob-image rancher/fleet:v0.10.2",
flags: map[string]string{},
},
{
cmd: "/sbin/agetty -o -p -- \\u --noclear - linux",
flags: map[string]string{
"o": "",
"p": "",
},
},
}

for i := range tests {
Expand Down

0 comments on commit 6c3502e

Please sign in to comment.