From 364565fc39daf09b13dda9336f938c68352150c5 Mon Sep 17 00:00:00 2001 From: Rohan Verma Date: Wed, 24 Oct 2018 13:28:10 +0530 Subject: feat: use flag library instead of custom flag parser --- up.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/up.go b/up.go index e89277e..74bea92 100644 --- a/up.go +++ b/up.go @@ -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 { -- cgit v1.2.3 From d23f52c45d98ac058eb3502e3ee8354e431cab0e Mon Sep 17 00:00:00 2001 From: Rohan Verma Date: Wed, 24 Oct 2018 14:16:50 +0530 Subject: feat: use pflag instead of flag --- go.mod | 1 + go.sum | 2 ++ up.go | 16 ++++------------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 01099d1..ecbfe90 100644 --- a/go.mod +++ b/go.mod @@ -6,5 +6,6 @@ require ( github.com/lucasb-eyer/go-colorful v0.0.0-20170903184257-231272389856 github.com/mattn/go-isatty v0.0.3 github.com/mattn/go-runewidth v0.0.2 + github.com/spf13/pflag v1.0.3 golang.org/x/text v0.0.0-20171214130843-f21a4dfb5e38 ) diff --git a/go.sum b/go.sum index bf01bbb..281ff67 100644 --- a/go.sum +++ b/go.sum @@ -8,5 +8,7 @@ github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= golang.org/x/text v0.0.0-20171214130843-f21a4dfb5e38 h1:yr7ItWHARpqySNZjEh5mPMHrw3xPR9tMnomFZVcO1mQ= golang.org/x/text v0.0.0-20171214130843-f21a4dfb5e38/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/up.go b/up.go index 74bea92..498e758 100644 --- a/up.go +++ b/up.go @@ -21,7 +21,6 @@ import ( "bufio" "bytes" "context" - "flag" "fmt" "io" "io/ioutil" @@ -30,6 +29,8 @@ import ( "os/exec" "sync" + flag "github.com/spf13/pflag" + "github.com/gdamore/tcell" "github.com/mattn/go-isatty" ) @@ -64,20 +65,15 @@ import ( // Flag Settings var ( - debugMode bool + debugMode = flag.Bool("debug", false, "debug mode") ) -func init() { - flag.BoolVar(&debugMode, "debug", false, "debug mode") - flag.BoolVar(&debugMode, "d", false, "debug mode (shorthand)") -} - func main() { // Handle command-line flags flag.Parse() log.SetOutput(ioutil.Discard) - if debugMode { + if *debugMode { debug, err := os.Create("up.debug") if err != nil { die(err.Error()) @@ -182,10 +178,6 @@ func main() { } } -func parseFlags() { - -} - func initTUI() tcell.Screen { // TODO: Without below block, we'd hang when nothing is piped on input (see // github.com/peco/peco, mattn/gof, fzf, etc.) -- cgit v1.2.3 From 3b5aa9593806db388af4a7436698b1babe5462aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Fri, 26 Oct 2018 00:07:17 +0200 Subject: implement my review requests --- up.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/up.go b/up.go index 498e758..0b7d1ca 100644 --- a/up.go +++ b/up.go @@ -29,10 +29,9 @@ import ( "os/exec" "sync" - flag "github.com/spf13/pflag" - "github.com/gdamore/tcell" "github.com/mattn/go-isatty" + "github.com/spf13/pflag" ) // TODO: some key shortcut to increase stdin capture buffer size (unless EOF already reached) @@ -63,14 +62,13 @@ 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 = flag.Bool("debug", false, "debug mode") + debugMode = pflag.Bool("debug", false, "debug mode") ) func main() { // Handle command-line flags - flag.Parse() + pflag.Parse() log.SetOutput(ioutil.Discard) if *debugMode { -- cgit v1.2.3 From 0181b7ee7ee92c3b76fe2043e70c86ee17384c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Czapli=C5=84ski?= Date: Fri, 26 Oct 2018 00:10:40 +0200 Subject: add missing AUTHORS file --- AUTHORS | 4 ++++ up.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..c7f2ac2 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,4 @@ +Please keep the contents of this file sorted alphabetically. + +Mateusz CzapliƄski +Rohan Verma diff --git a/up.go b/up.go index 0b7d1ca..0bd7a3f 100644 --- a/up.go +++ b/up.go @@ -1,4 +1,4 @@ -// Copyright 2018 The up Authors +// Copyright 2018 The up AUTHORS // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. -- cgit v1.2.3