github.com/comcast/canticle@v0.0.0-20161108184242-c53cface56e8/cant/cant.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "flag" 6 "fmt" 7 "log" 8 "os" 9 "text/template" 10 11 "github.com/Comcast/Canticle/buildinfo" 12 "github.com/Comcast/Canticle/canticles" 13 ) 14 15 // Canticle will: 16 // Load deps files 17 // Make the working dir _workspace 18 // Grab the deps listed in the file (all deps must be listed), it may grab from an alternative url 19 // Import the deps 20 // No rewrite necessary..., just overload gopath 21 // Copy your current _workspace into in the correct place 22 // Call build/test/whatever 23 // Copy the result back out 24 func main() { 25 versionFlag := flag.Bool("version", false, "version prints the version info of canticle") 26 flag.Usage = usage 27 flag.Parse() 28 log.SetFlags(0) 29 30 if *versionFlag { 31 b, err := json.MarshalIndent(buildinfo.GetBuildInfo(), "", " ") 32 if err != nil { 33 log.Fatalf("Error marshaling own buildinfo!: %s", err.Error()) 34 } 35 log.Printf("BuildInfo: \n%s\n", string(b)) 36 return 37 } 38 39 args := flag.Args() 40 if len(args) < 1 { 41 usage() 42 } 43 44 cmdName := args[0] 45 cmd, ok := canticles.Commands[cmdName] 46 if !ok { 47 fmt.Fprintln(os.Stderr, "Unkown subcommand ", cmdName) 48 usage() 49 } 50 51 cmd.Flags.Usage = cmd.Usage 52 cmd.Flags.Parse(args[1:]) 53 cmd.Cmd.Run(args[1:]) 54 } 55 56 var UsageTemplate = `Canticle is a tool for managing go dependencies. 57 58 Usage: 59 cant command [arguments] 60 61 The commands are: 62 {{range .}} 63 {{.Name | printf "%-11s"}} {{.ShortDescription}}{{end}} 64 65 Use "cant help [command]" for more information about that command. 66 ` 67 68 func usage() { 69 tmpl, _ := template.New("UsageTemplate").Parse(UsageTemplate) 70 tmpl.Execute(os.Stderr, canticles.Commands) 71 os.Exit(2) 72 }