From fe8a936176c220bcd4c499ac421136fb586675b8 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 8 Jun 2019 12:39:55 +0200 Subject: [PATCH] nsscash: add "fetch" sub-command for the default action In preparation for more sub-commands in the future. --- main.go | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 5026387..3b2dba8 100644 --- a/main.go +++ b/main.go @@ -18,17 +18,35 @@ package main import ( + "flag" + "fmt" "log" "os" ) func main() { - if len(os.Args) != 2 { - log.SetFlags(0) - log.Fatalf("usage: %s \n", os.Args[0]) + flag.Usage = func() { + fmt.Fprintf(os.Stderr, + "usage: %[1]s [options] fetch \n"+ + "", + os.Args[0]) + flag.PrintDefaults() } + flag.Parse() - cfg, err := LoadConfig(os.Args[1]) + args := flag.Args() + if len(args) == 0 { + flag.Usage() + os.Exit(1) + } + + switch args[0] { + case "fetch": + if len(args) != 2 { + break + } + + cfg, err := LoadConfig(args[1]) if err != nil { log.Fatal(err) } @@ -46,4 +64,10 @@ func main() { if err != nil { log.Fatal(err) } + + return + } + + flag.Usage() + os.Exit(1) } -- 2.45.2