From af8f52e2e4c879935656dd93c2fb564c6e2ce515 Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Thu, 22 Jul 2021 00:41:30 -0500 Subject: Parse within subcommands --- cmd/list.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'cmd/list.go') diff --git a/cmd/list.go b/cmd/list.go index d2b9a03..99d5f24 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -1,8 +1,8 @@ package cmd import ( - "flag" "fmt" + "flag" ) func List(params []string) { @@ -10,12 +10,28 @@ func List(params []string) { var withPaths bool - const WITH_PATHS_HELP = "print paths to the provided reference within the snapshot" + withName := aliasedBoolVar( + flags, + &withPaths, + false, + "print paths to the provided reference within the snapshot", + ) - flags.BoolVar(&withPaths, "paths", false, WITH_PATHS_HELP); - flags.BoolVar(&withPaths, "p", false, WITH_PATHS_HELP); + withName("paths") + withName("p") flags.Parse(params); + if(flags.NArg() == 0) { + die.Fatal("Reference file is required") + } + + if(flags.NArg() > 1) { + die.Fatal("Too many arguments provided") + } + + reference := flags.Arg(0) + + fmt.Printf(reference) fmt.Printf("Your flag is: %t", withPaths); } -- cgit v1.2.3