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 91ec219 commit 53bea4f
Show file tree
Hide file tree
Showing 2 changed files with 19 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 @@ -13,6 +13,7 @@ var (
runDir string
materialsPaths []string
productsPaths []string
noCommand bool
)

var runCmd = &cobra.Command{
Expand All @@ -23,7 +24,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: getKeyCert,
RunE: run,
}
Expand Down Expand Up @@ -131,6 +132,14 @@ 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.`,
)

runCmd.Flags().StringVar(
&spiffeUDS,
"spiffe-workload-api-path",
Expand All @@ -141,6 +150,14 @@ with a new line character.`,
}

func run(cmd *cobra.Command, args []string) error {
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")
}

block, err := intoto.InTotoRun(stepName, runDir, materialsPaths, productsPaths, args, key, []string{"sha256"}, exclude, lStripPaths, lineNormalization)
if err != nil {
return fmt.Errorf("failed to create link metadata: %w", err)
Expand Down
1 change: 1 addition & 0 deletions doc/in-toto_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ in-toto run [flags]
-d, --metadata-directory string Directory to store link metadata (default "./")
-n, --name string Name used to associate the resulting link metadata
with the corresponding step defined in an in-toto layout.
-x, --no-command Indicate that there is no command to be executed for the step.
--normalize-line-endings Enable line normalization in order to support different
operating systems. It is done by replacing all line separators
with a new line character.
Expand Down

0 comments on commit 53bea4f

Please sign in to comment.