github.com/hwaf/hwaf@v0.0.0-20140814122253-5465f73b20f1/cmd_self_init.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/gonuts/commander" 8 "github.com/gonuts/flag" 9 ) 10 11 func hwaf_make_cmd_self_init() *commander.Command { 12 cmd := &commander.Command{ 13 Run: hwaf_run_cmd_self_init, 14 UsageLine: "init [options] <workarea>", 15 Short: "initialize hwaf itself", 16 Long: ` 17 init initializes hwaf internal files. 18 19 ex: 20 $ hwaf self init 21 `, 22 Flag: *flag.NewFlagSet("hwaf-self-init", flag.ExitOnError), 23 } 24 cmd.Flag.Bool("v", false, "enable verbose output") 25 26 return cmd 27 } 28 29 func hwaf_run_cmd_self_init(cmd *commander.Command, args []string) error { 30 var err error 31 n := "hwaf-self-" + cmd.Name() 32 33 switch len(args) { 34 case 0: 35 // ok 36 default: 37 return fmt.Errorf("%s: does NOT take any argument", n) 38 } 39 40 verbose := cmd.Flag.Lookup("v").Value.Get().(bool) 41 42 if verbose { 43 fmt.Printf("%s...\n", n) 44 } 45 46 hwaf_root := os.Getenv("HWAF_ROOT") 47 for _, dir := range []string{g_ctx.Root, hwaf_root} { 48 if dir != "" { 49 g_ctx.Warnf("you are trying to 'hwaf self init' while running a HWAF_ROOT-based installation\n") 50 g_ctx.Warnf("this is like crossing the streams in Ghostbusters (ie: it's bad.)\n") 51 g_ctx.Warnf("if you think you know what you are doing, unset HWAF_ROOT and re-run 'hwaf self init'\n") 52 return fmt.Errorf("${HWAF_ROOT} was set (%s)", dir) 53 } 54 } 55 56 // 'hwaf self init' is now dummied out... 57 58 if verbose { 59 fmt.Printf("%s... [ok]\n", n) 60 } 61 62 return err 63 } 64 65 // EOF