From 7f37cc53073e61831365b157916810b32161c6e0 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Sat, 27 Jan 2018 09:47:43 +0100 Subject: [PATCH] Reordering --- job_ui.go | 18 ++++++++++++++++++ main.go | 27 +++++---------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/job_ui.go b/job_ui.go index bca2246..88fd218 100644 --- a/job_ui.go +++ b/job_ui.go @@ -1,5 +1,7 @@ package main +import "time" + // ui-ideas // // * https://godoc.org/github.com/jroimartin/gocui @@ -33,3 +35,19 @@ type JobUI interface { JobDone(jobID string) Wait() // wait for all jobs to be .Done() } + +func newUI(ui string) JobUI { + switch ui { + case "oneline": + return &UIOneLine{ + pt: newProgressTicker(0), + prefix: "vopher", + duration: 25 * time.Millisecond, + } + case "simple": + return &UISimple{jobs: make(map[string]Runtime)} + case "quiet": + return &UIQuiet{} + } + return nil +} diff --git a/main.go b/main.go index d54237f..a3f0866 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,6 @@ import ( "log" "os" "strings" - "time" ) var allowedActions = []string{ @@ -131,17 +130,17 @@ func main() { if cli.action == "search" && len(flag.Args()) < 2 { log.Fatal("error: missing arguments for 'search'") - } else if cli.action == "fetch" && len(flag.Args()) < 2 { + } + if cli.action == "fetch" && len(flag.Args()) < 2 { log.Fatal("error: missing arguments for 'fetch'") } - - cli.ui = defaultUI(cli.ui, cli.action) - var ui JobUI = generateUI(cli.ui) - if cli.dir == "" { log.Fatal("error: empty -dir") } + cli.ui = defaultUI(cli.ui, cli.action) + ui := newUI(cli.ui) + path, err := expandPath(cli.dir) if err != nil { log.Fatalf("error: expanding %q failed while obtaining current user?? %s", cli.dir, err) @@ -195,22 +194,6 @@ func defaultUI(ui, action string) string { } } -func generateUI(ui string) JobUI { - switch ui { - case "oneline": - return &UIOneLine{ - pt: newProgressTicker(0), - prefix: "vopher", - duration: 25 * time.Millisecond, - } - case "simple": - return &UISimple{jobs: make(map[string]Runtime)} - case "quiet": - return &UIQuiet{} - } - return nil -} - func mayReadPlugins(path string, parse PluginParser, filter stringList) PluginList { plugins := make(PluginList) parse(plugins, path)