From 6b7fd100809a245d1bcdcf4c4a98f619a1ae7aeb Mon Sep 17 00:00:00 2001 From: YoannGh Date: Thu, 14 Dec 2023 11:52:16 +0100 Subject: [PATCH] add support for providing executable arguments --- .../subcommands/selftestscmd/selftests.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/cws-instrumentation/subcommands/selftestscmd/selftests.go b/cmd/cws-instrumentation/subcommands/selftestscmd/selftests.go index 482dc17111775..4908862b7fbf6 100644 --- a/cmd/cws-instrumentation/subcommands/selftestscmd/selftests.go +++ b/cmd/cws-instrumentation/subcommands/selftestscmd/selftests.go @@ -12,6 +12,7 @@ import ( "errors" "os" "os/exec" + "strings" "github.com/spf13/cobra" ) @@ -19,6 +20,7 @@ import ( type execParams struct { enabled bool path string + args string } type openParams struct { @@ -52,6 +54,7 @@ func Command() []*cobra.Command { selftestsCmd.Flags().BoolVar(¶ms.exec.enabled, "exec", false, "run the exec selftest") selftestsCmd.Flags().StringVar(¶ms.exec.path, "exec.path", "/usr/bin/date", "path to the file to execute") + selftestsCmd.Flags().StringVar(¶ms.exec.args, "exec.args", "", "arguments to pass to the executable") selftestsCmd.Flags().BoolVar(¶ms.open.enabled, "open", false, "run the open selftest") selftestsCmd.Flags().StringVar(¶ms.open.path, "open.path", "/tmp/open.test", "path to the file to open") @@ -59,6 +62,9 @@ func Command() []*cobra.Command { } func selftestExec(params *execParams) error { + if params.args != "" { + return exec.Command(params.path, strings.Split(params.args, " ")...).Run() + } return exec.Command(params.path).Run() }