fix help, short names for options
This commit is contained in:
parent
20a2befa34
commit
26e00210aa
|
@ -0,0 +1,3 @@
|
|||
# Chinampa
|
||||
|
||||
Like [`milpa`](https://milpa.dev) but for go programs only.
|
|
@ -218,9 +218,13 @@ func Execute(version string) error {
|
|||
}
|
||||
cmdRoot.SetCobra(ccRoot)
|
||||
|
||||
err := ccRoot.Execute()
|
||||
current, _, err := ccRoot.Find(os.Args[1:])
|
||||
if err != nil {
|
||||
errors.HandleCobraExit(ccRoot, err)
|
||||
current = ccRoot
|
||||
}
|
||||
err = current.Execute()
|
||||
if err != nil {
|
||||
errors.HandleCobraExit(current, err)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
|
@ -81,14 +81,15 @@ func (cmd *Command) FlagSet() *pflag.FlagSet {
|
|||
if opt.Default != nil {
|
||||
def = opt.Default.(bool)
|
||||
}
|
||||
fs.Bool(name, def, opt.Description)
|
||||
|
||||
fs.BoolP(name, opt.ShortName, def, opt.Description)
|
||||
case ValueTypeDefault, ValueTypeString:
|
||||
opt.Type = ValueTypeString
|
||||
def := ""
|
||||
if opt.Default != nil {
|
||||
def = fmt.Sprintf("%s", opt.Default)
|
||||
}
|
||||
fs.String(name, def, opt.Description)
|
||||
fs.StringP(name, opt.ShortName, def, opt.Description)
|
||||
default:
|
||||
// ignore flag
|
||||
logrus.Warnf("Ignoring unknown option type <%s> for option <%s>", opt.Type, name)
|
||||
|
@ -113,6 +114,7 @@ func (cmd *Command) ParseInput(cc *cobra.Command, args []string) error {
|
|||
|
||||
logrus.Debug("Validating flags")
|
||||
if err := cmd.Options.AreValid(); err != nil {
|
||||
logrus.Debug("Invalid flags for %s: %w", cmd.FullName(), err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -124,6 +126,7 @@ func (cmd *Command) Run(cc *cobra.Command, args []string) error {
|
|||
logrus.Debugf("running command %s", cmd.FullName())
|
||||
|
||||
if err := cmd.ParseInput(cc, args); err != nil {
|
||||
logrus.Debugf("Parsing input to command %s failed: %s", cmd.FullName(), err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue