Skip to content

Commit

Permalink
add support for providing executable arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannGh committed Dec 14, 2023
1 parent 82516ac commit 6b7fd10
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/cws-instrumentation/subcommands/selftestscmd/selftests.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import (
"errors"
"os"
"os/exec"
"strings"

"github.com/spf13/cobra"
)

type execParams struct {
enabled bool
path string
args string
}

type openParams struct {
Expand Down Expand Up @@ -52,13 +54,17 @@ func Command() []*cobra.Command {

selftestsCmd.Flags().BoolVar(&params.exec.enabled, "exec", false, "run the exec selftest")
selftestsCmd.Flags().StringVar(&params.exec.path, "exec.path", "/usr/bin/date", "path to the file to execute")
selftestsCmd.Flags().StringVar(&params.exec.args, "exec.args", "", "arguments to pass to the executable")
selftestsCmd.Flags().BoolVar(&params.open.enabled, "open", false, "run the open selftest")
selftestsCmd.Flags().StringVar(&params.open.path, "open.path", "/tmp/open.test", "path to the file to open")

return []*cobra.Command{selftestsCmd}
}

func selftestExec(params *execParams) error {
if params.args != "" {
return exec.Command(params.path, strings.Split(params.args, " ")...).Run()
}
return exec.Command(params.path).Run()
}

Expand Down

0 comments on commit 6b7fd10

Please sign in to comment.