"Fossies" - the Fresh Open Source Software Archive

Member "geoipupdate-4.3.0/cmd/geoipupdate/args.go" (16 Apr 2020, 1307 Bytes) of package /linux/misc/geoipupdate-4.3.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "args.go": 4.1.4_vs_4.1.5.

    1 package main
    2 
    3 import (
    4     "log"
    5     "os"
    6 
    7     flag "github.com/spf13/pflag"
    8 )
    9 
   10 // Args are command line arguments.
   11 type Args struct {
   12     ConfigFile        string
   13     DatabaseDirectory string
   14     StackTrace        bool
   15     Verbose           bool
   16 }
   17 
   18 func getArgs() *Args {
   19     configFile := flag.StringP(
   20         "config-file",
   21         "f",
   22         defaultConfigFile,
   23         "Configuration file",
   24     )
   25     databaseDirectory := flag.StringP(
   26         "database-directory",
   27         "d",
   28         "",
   29         "Store databases in this directory (uses config if not specified)",
   30     )
   31     help := flag.BoolP("help", "h", false, "Display help and exit")
   32     stackTrace := flag.Bool("stack-trace", false, "Show a stack trace along with any error message.")
   33     verbose := flag.BoolP("verbose", "v", false, "Use verbose output")
   34     displayVersion := flag.BoolP("version", "V", false, "Display the version and exit")
   35 
   36     flag.Parse()
   37 
   38     if *help {
   39         printUsage()
   40     }
   41     if *displayVersion {
   42         log.Printf("geoipupdate %s", version)
   43         os.Exit(0)
   44     }
   45 
   46     if *configFile == "" {
   47         log.Printf("You must provide a configuration file.")
   48         printUsage()
   49     }
   50 
   51     return &Args{
   52         ConfigFile:        *configFile,
   53         DatabaseDirectory: *databaseDirectory,
   54         StackTrace:        *stackTrace,
   55         Verbose:           *verbose,
   56     }
   57 }
   58 
   59 func printUsage() {
   60     log.Printf("Usage: %s <arguments>\n", os.Args[0])
   61     flag.PrintDefaults()
   62     os.Exit(1)
   63 }