diff options
author | Rohan Verma <hello@rohanverma.net> | 2018-10-24 13:28:10 +0530 |
---|---|---|
committer | Rohan Verma <hello@rohanverma.net> | 2018-10-24 13:28:10 +0530 |
commit | 364565fc39daf09b13dda9336f938c68352150c5 (patch) | |
tree | a7f04a204bf36e6c07f59c23695338b162d4fd23 | |
parent | f1d4bb8f864f3318c2561ac04f2a2e158f19c6bb (diff) |
feat: use flag library instead of custom flag parser
-rw-r--r-- | up.go | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -21,6 +21,7 @@ import ( "bufio" "bytes" "context" + "flag" "fmt" "io" "io/ioutil" @@ -61,9 +62,28 @@ import ( // TODO: [LATER] make it more friendly to infrequent Linux users by providing "descriptive" commands like "search" etc. // TODO: [LATER] advertise on: HN, r/programming, r/golang, r/commandline, r/linux, up-for-grabs.net; data exploration? data science? +// Flag Settings +var ( + debugMode bool +) + +func init() { + flag.BoolVar(&debugMode, "debug", false, "debug mode") + flag.BoolVar(&debugMode, "d", false, "debug mode (shorthand)") +} + func main() { // Handle command-line flags - parseFlags() + flag.Parse() + + log.SetOutput(ioutil.Discard) + if debugMode { + debug, err := os.Create("up.debug") + if err != nil { + die(err.Error()) + } + log.SetOutput(debug) + } // Initialize TUI infrastructure tui := initTUI() @@ -163,14 +183,7 @@ func main() { } func parseFlags() { - log.SetOutput(ioutil.Discard) - if len(os.Args) > 1 && os.Args[1] == "--debug" { - debug, err := os.Create("up.debug") - if err != nil { - die(err.Error()) - } - log.SetOutput(debug) - } + } func initTUI() tcell.Screen { |