Skip to content

Commit

Permalink
Improve null consumer
Browse files Browse the repository at this point in the history
Do not require 2 arguments when using null consumer.

Multifile manifest still requires a target. This is to maintain continuity
in the manifest parsing code.

Closes: #102
  • Loading branch information
tempusfrangit committed Feb 20, 2024
1 parent 5f3841e commit afcbff4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetCommand() *cobra.Command {
PersistentPostRunE: rootPersistentPostRunEFunc,
PreRun: rootCmdPreRun,
RunE: runRootCMD,
Args: cobra.ExactArgs(2),
Args: validateArgs,
Example: ` pget https://example.com/file.tar ./target-dir`,
}
cmd.Flags().BoolP(config.OptExtract, "x", false, "OptExtract archive after download")
Expand Down Expand Up @@ -259,3 +259,10 @@ func rootExecute(ctx context.Context, urlString, dest string) error {
_, _, err = getter.DownloadFile(ctx, urlString, dest)
return err
}

func validateArgs(cmd *cobra.Command, args []string) error {
if viper.GetString(config.OptOutputConsumer) == config.ConsumerNull {
return cobra.RangeArgs(1, 2)(cmd, args)
}
return cobra.ExactArgs(2)(cmd, args)
}

0 comments on commit afcbff4

Please sign in to comment.