diff --git a/cmd/run.go b/cmd/run.go index 832518de..cbe6d319 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -14,6 +14,7 @@ var ( runDir string materialsPaths []string productsPaths []string + noCommand bool ) var runCmd = &cobra.Command{ @@ -24,7 +25,7 @@ files before command execution) and 'products' (i.e. files after command execution) and stores them together with other information (executed command, return value, stdout, stderr, ...) to a link metadata file, which is signed with the passed key. Returns nonzero value on failure and zero otherwise.`, - Args: cobra.MinimumNArgs(1), + Args: cobra.MinimumNArgs(0), PreRunE: runPreRun, RunE: run, } @@ -131,6 +132,14 @@ in environment variables or config files. See Config docs for details.`, operating systems. It is done by replacing all line separators with a new line character.`, ) + + runCmd.Flags().BoolVarP( + &noCommand, + "no-command", + "x", + false, + `Indicate that there is no command to be executed for the step.`, + ) } func runPreRun(cmd *cobra.Command, args []string) error { @@ -161,6 +170,14 @@ func runPreRun(cmd *cobra.Command, args []string) error { return fmt.Errorf("cert not found at %s: %w", certPath, err) } } + + if noCommand && len(args) > 0 { + return fmt.Errorf("command arguments passed with --no-command/-x flag") + } + + if !noCommand && len(args) == 0 { + return fmt.Errorf("no command arguments passed, please specify or use --no-command option") + } return nil }