From 7c9ea276ac69130229f4ae35547288fe8429f6f1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 7 Mar 2023 01:45:05 -0700 Subject: cmd/btrfs-rec: Don't require --pv for `help` --- cmd/btrfs-rec/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cmd/btrfs-rec') diff --git a/cmd/btrfs-rec/main.go b/cmd/btrfs-rec/main.go index 5da8f52..343a41f 100644 --- a/cmd/btrfs-rec/main.go +++ b/cmd/btrfs-rec/main.go @@ -86,7 +86,6 @@ func main() { argparser.PersistentFlags().StringArrayVar(&globalFlags.pvs, "pv", nil, "open the file `physical_volume` as part of the filesystem") noError(argparser.MarkPersistentFlagFilename("pv")) - noError(argparser.MarkPersistentFlagRequired("pv")) argparser.PersistentFlags().StringVar(&globalFlags.mappings, "mappings", "", "load chunk/dev-extent/blockgroup data from external JSON file `mappings.json`") noError(argparser.MarkPersistentFlagFilename("mappings")) @@ -130,6 +129,11 @@ func runWithRawFS(runE func(*btrfs.FS, *cobra.Command, []string) error) func(*co defer func() { maybeSetErr(globalFlags.stopProfiling()) }() + if len(globalFlags.pvs) == 0 { + // We do this here instead of calling argparser.MarkPersistentFlagRequired("pv") so that + // it doesn't interfere with the `help` sub-command. + return cliutil.FlagErrorFunc(cmd, fmt.Errorf("must specify 1 or more physical volumes with --pv")) + } fs, err := btrfsutil.Open(ctx, globalFlags.openFlag, globalFlags.pvs...) if err != nil { return err -- cgit v1.2.3-2-g168b