Beispiel #1
0
func runInit(cfg *conf.Config, dir string) error {
	dir = util.DefaultString(dir, ".")
	if conf.Exists(dir) {
		confirmed, _ := util.Confirm(fmt.Sprintf("%s already exists. Do you want to overwrite it with the default configuration (yN)? ", conf.ConfName))
		if !confirmed {
			fmt.Println("aborting init")
			return nil
		}
	}
	return conf.Init(dir)
}
Beispiel #2
0
func Run(cmdName string, arg string) error {
	c := Lookup(cmdName)
	if c == nil {
		return fmt.Errorf("invalid subcommand: %s", cmdName)
	}

	if c.NeedsConf {
		arg := util.DefaultString(arg, ".")
		if !conf.Exists(arg) {
			return missingConfError(arg)
		} else {
			cfg, err := conf.Parse(arg)
			if err != nil {
				return err
			}
			return c.Handler(cfg, arg)
		}
	} else {
		return c.Handler(nil, arg)
	}
}