Skip to content

Commit

Permalink
Add CLI flag --no-command
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Sirish <aditya@saky.in>
  • Loading branch information
adityasaky committed Oct 13, 2022
1 parent 3508787 commit 8fbc953
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
runDir string
materialsPaths []string
productsPaths []string
noCommand bool
)

var runCmd = &cobra.Command{
Expand All @@ -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,
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 8fbc953

Please sign in to comment.