From 9097bb4f6b532a323a25ced2deb10b9f53860348 Mon Sep 17 00:00:00 2001 From: yory8 <> Date: Sun, 27 Oct 2019 16:00:51 +0100 Subject: [PATCH] refac: remove some duplication --- main.go | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/main.go b/main.go index 1a0c94f..3af1862 100644 --- a/main.go +++ b/main.go @@ -41,13 +41,15 @@ func main() { app.Version(version) app.HelpFlag.Short('h') app.VersionFlag.Short('v') - switch kingpin.MustParse(app.Parse(os.Args[1:])) { - case "store": - histfile, history, err := getHistory(*histpath) - if err != nil { - log.Fatal(err) - } + action := kingpin.MustParse(app.Parse(os.Args[1:])) + histfile, history, err := getHistory(*histpath) + if err != nil { + log.Fatal(err) + } + + switch action { + case "store": // read copy from stdin var stdin []string scanner := bufio.NewScanner(os.Stdin) @@ -64,11 +66,6 @@ func main() { log.Fatal(err) } case "pick": - _, history, err := getHistory(*histpath) - if err != nil { - log.Fatal(err) - } - selection, err := selector(history, *maxPicker, *pickTool, "pick", *pickToolArgs) if err != nil { log.Fatal(err) @@ -81,11 +78,6 @@ func main() { } } case "restore": - _, history, err := getHistory(*histpath) - if err != nil { - log.Fatal(err) - } - if len(history) == 0 { log.Println("Nothing to restore") return @@ -95,11 +87,6 @@ func main() { log.Fatal(err) } case "clear": - histfile, history, err := getHistory(*histpath) - if err != nil { - log.Fatal(err) - } - // remove all history if *clearAll { if err := wipeAll(histfile); err != nil {