Example #1
0
func configCmd(c *commander.Command, args []string) error {
	if c.Flag.Lookup("show").Value.Get().(bool) {
		return printConfig(&Config)
	}

	if c.Flag.Lookup("edit").Value.Get().(bool) {
		return configEditor()
	}

	if len(args) == 0 {
		return fmt.Errorf("%s: requires <key> argument.", c.Name())
	}

	if len(args) == 1 {
		value := ConfigGet(args[0])
		if value == nil {
			return fmt.Errorf("") // empty string prints out nothing.
		}

		m, err := Marshal(value)
		if err != nil {
			return err
		}
		io.Copy(os.Stdout, m)
		return nil
	}

	return ConfigSet(args[0], args[1])
}
func ex_run_cmd_subcmd2_cmd2(cmd *commander.Command, args []string) error {
	name := "my-cmd-subcmd2-" + cmd.Name()
	quiet := cmd.Flag.Lookup("q").Value.Get().(bool)
	fmt.Printf("%s: hello from subcmd2-cmd2 (quiet=%v)\n", name, quiet)
	return nil
}