github.com/hwaf/hwaf@v0.0.0-20140814122253-5465f73b20f1/main.go (about) 1 /* 2 hwaf manages hep-waf based applications and libraries. 3 4 Subcommands: 5 6 init [directory] 7 8 self-update 9 10 configure 11 12 build/make 13 14 install 15 16 bdist 17 bdist-rpm 18 bdist-dmg 19 bdist-deb 20 21 run 22 23 shell 24 25 setup 26 27 add-pkg <pkg-uri> [<pkg-version>] 28 checkout|co == alias(add-pkg) 29 */ 30 package main 31 32 import ( 33 "os" 34 "path/filepath" 35 36 "github.com/gonuts/commander" 37 "github.com/gonuts/flag" 38 "github.com/hwaf/hwaf/hwaflib" 39 ) 40 41 var g_cmd *commander.Command 42 var g_ctx *hwaflib.Context 43 44 func init() { 45 g_cmd = &commander.Command{ 46 UsageLine: "hwaf", 47 Subcommands: []*commander.Command{ 48 hwaf_make_cmd_asetup(), 49 hwaf_make_cmd_init(), 50 hwaf_make_cmd_setup(), 51 hwaf_make_cmd_version(), 52 53 hwaf_make_cmd_waf(), 54 hwaf_make_cmd_waf_configure(), 55 hwaf_make_cmd_waf_build(), 56 hwaf_make_cmd_waf_check(), 57 hwaf_make_cmd_waf_install(), 58 hwaf_make_cmd_waf_clean(), 59 hwaf_make_cmd_waf_distclean(), 60 hwaf_make_cmd_waf_shell(), 61 hwaf_make_cmd_waf_run(), 62 63 hwaf_make_cmd_waf_sdist(), 64 hwaf_make_cmd_waf_bdist(), 65 hwaf_make_cmd_waf_bdist_deb(), 66 hwaf_make_cmd_waf_bdist_dmg(), 67 hwaf_make_cmd_waf_bdist_rpm(), 68 69 hwaf_make_cmd_dump_env(), 70 71 hwaf_make_cmd_git(), 72 hwaf_make_cmd_pkg(), 73 hwaf_make_cmd_waf_show(), 74 hwaf_make_cmd_pmgr(), 75 hwaf_make_cmd_self(), 76 }, 77 Flag: *flag.NewFlagSet("hwaf", flag.ExitOnError), 78 } 79 } 80 81 func main() { 82 83 var err error 84 pwd, err := os.Getwd() 85 handle_err(err) 86 87 wdir := pwd 88 if len(os.Args) > 1 { 89 switch os.Args[1] { 90 case "init", "setup", "asetup": 91 // these are supposed to *create* the .hwaf directory... 92 93 default: 94 wdir = func() string { 95 // try to find a workarea in a parent dir: 96 for dir := wdir; dir != "/"; dir = filepath.Dir(dir) { 97 if path_exists(filepath.Join(dir, ".hwaf")) { 98 return dir 99 } 100 } 101 return "" 102 }() 103 } 104 } 105 106 switch wdir { 107 case "": 108 g_ctx, err = hwaflib.NewContext() 109 handle_err(err) 110 default: 111 g_ctx, err = hwaflib.NewContextFrom(wdir) 112 handle_err(err) 113 } 114 115 if len(os.Args) == 1 { 116 if path_exists("wscript") { 117 os.Args = append(os.Args, "waf", "build+install") 118 } else { 119 g_ctx.Errorf("'hwaf' needs a command to run (or be executed from a directory containing a wscript file.)\n") 120 g_ctx.Errorf("run 'hwaf help' for informations\n") 121 os.Exit(1) 122 } 123 } 124 125 err = g_cmd.Flag.Parse(os.Args[1:]) 126 handle_err(err) 127 128 args := g_cmd.Flag.Args() 129 err = g_cmd.Dispatch(args) 130 handle_err(err) 131 132 g_ctx.Exit(0) 133 return 134 }