From: Simon Ruderich Date: Sat, 8 Jun 2019 10:39:55 +0000 (+0200) Subject: nsscash: add "fetch" sub-command for the default action X-Git-Tag: 0.1~96 X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=fe8a936176c220bcd4c499ac421136fb586675b8;p=nsscash%2Fnsscash.git nsscash: add "fetch" sub-command for the default action In preparation for more sub-commands in the future. --- 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) }