From a92faf7689fa01595fd613ddd3880e9c301ed558 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 9 May 2017 21:32:16 +0200 Subject: refactor cli.Interface yet again - Only one global instance now, so we don't need to pass it around all the time. - Allow to swap out the Command.Run implementation for unit tests. - Can now use cli.Interface during func init() of packages importing pkg/cli. --- main.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 30ae9c4..03dc9de 100644 --- a/main.go +++ b/main.go @@ -29,30 +29,29 @@ import ( ) func main() { - ci := cli.NewInterface(os.Stdin, os.Stdout, os.Stderr) if len(earlyerrors.Get()) > 0 { for _, msg := range earlyerrors.Get() { - ci.ShowError(msg) + cli.Interface.ShowError(msg) } os.Exit(255) } - os.Exit(execApplet(ci, filepath.Base(os.Args[0]), os.Args[1:], true)) + os.Exit(execApplet(filepath.Base(os.Args[0]), os.Args[1:], true)) } -func execApplet(ci *cli.Interface, applet string, args []string, allowGofu bool) int { +func execApplet(applet string, args []string, allowGofu bool) int { //allow explicit specification of applet as "./build/gofu " if allowGofu && applet == "gofu" { if len(args) == 0 { fmt.Fprintln(os.Stderr, "Usage: gofu [args...]") return 1 } - return execApplet(ci, args[0], args[1:], false) + return execApplet(args[0], args[1:], false) } switch applet { case "rtree": - return rtree.Exec(ci, args) + return rtree.Exec(args) default: fmt.Fprintln(os.Stderr, "ERROR: unknown applet: "+applet) return 255 -- cgit v1.3.1