From 72733e8203654cd26464c8c5a6c955b025102cca Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 2 May 2017 21:22:20 +0200 Subject: restructure rtree into gofu (with rtree as the first applet) --- main.go | 91 +++++++++++------------------------------------------------------ 1 file changed, 15 insertions(+), 76 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 40e6630..72768ea 100644 --- a/main.go +++ b/main.go @@ -21,89 +21,28 @@ package main import ( "fmt" "os" + "path/filepath" + + "github.com/majewsky/gofu/pkg/rtree" ) func main() { - if len(os.Args) == 1 { - usageAndExit() - } - switch os.Args[1] { - case "get": - panic("unimplemented") - case "drop": - panic("unimplemented") - case "index": - if len(os.Args) != 2 { - usageAndExit() - } - commandIndex() - case "repos": - if len(os.Args) != 2 { - usageAndExit() - } - commandRepos() - case "remotes": - if len(os.Args) != 2 { - usageAndExit() - } - commandRemotes() - case "import": - panic("unimplemented") - case "each": - if len(os.Args) < 3 { - usageAndExit() - } - commandEach(os.Args[2], os.Args[3:]) - default: - usageAndExit() - } -} - -func usageAndExit() { - fmt.Fprintln(os.Stderr, "Usage:") - fmt.Fprintln(os.Stderr, " rtree [get|drop] ") - fmt.Fprintln(os.Stderr, " rtree [index|repos|remotes]") - fmt.Fprintln(os.Stderr, " rtree import ") - fmt.Fprintln(os.Stderr, " rtree each ") - os.Exit(1) -} - -func commandIndex() { - index := ReadIndex() - FatalIfError(index.InteractiveRebuild()) - index.Write() -} - -func commandRepos() { - index := ReadIndex() - var items []string - for _, repo := range index.Repos { - items = append(items, repo.CheckoutPath) - } - ShowSorted(items) -} - -func commandRemotes() { - index := ReadIndex() - var items []string - for _, repo := range index.Repos { - for _, remote := range repo.Remotes { - items = append(items, remote.URL) - } - } - ShowSorted(items) + execApplet(filepath.Base(os.Args[0]), os.Args[1:], true) } -func commandEach(command string, args []string) { - allOK := true - for _, repo := range ReadIndex().Repos { - ok := repo.InteractiveExec(command, args...) - if !ok { - allOK = false +func execApplet(applet string, args []string, allowGofu bool) { + //allow explicit specification of applet as "./build/gofu " + if allowGofu && applet == "gofu" { + if len(args) == 0 { + fmt.Fprintln(os.Stderr, "Usage: gofu [args...]") + os.Exit(1) } + execApplet(args[0], args[1:], false) + return } - if !allOK { - os.Exit(1) + switch applet { + case "rtree": + rtree.Exec(args) } } -- cgit v1.3.1