diff --git a/cobra/configure.go b/cobra/configure.go index 1aab6145..ae64903d 100644 --- a/cobra/configure.go +++ b/cobra/configure.go @@ -107,7 +107,7 @@ func (c *cobra) ConfigureWriteConfig(basename string, defaultConfig func() io.Re } default: buf = defaultConfig() - cfgFile = strings.TrimRight(cfgFile, ext) + ".json" + cfgFile = strings.TrimSuffix(cfgFile, ext) + ".json" } // #nosec @@ -189,14 +189,14 @@ func (c *cobra) jsonToYaml(r io.Reader) (io.Reader, error) { } } -func (c *cobra) AddCommandConfigure(basename string, defaultConfig func() io.Reader) { +func (c *cobra) AddCommandConfigure(alias, basename string, defaultConfig func() io.Reader) { pkg := c.getPackageName() if basename == "" && pkg != "" { basename = "." + strings.ToLower(pkg) } - c.c.AddCommand(&spfcbr.Command{ + cmd := &spfcbr.Command{ Use: "configure ", Example: "configure ~/." + strings.ToLower(pkg) + ".yml", Short: "Generate config file", @@ -210,5 +210,11 @@ override by passed flag in command line and completed with default for non exist Args: func(cmd *spfcbr.Command, args []string) error { return c.ConfigureCheckArgs(basename, args) }, - }) + } + + if len(alias) > 0 { + cmd.Aliases = []string{alias} + } + + c.c.AddCommand(cmd) } diff --git a/cobra/interface.go b/cobra/interface.go index 5a1b54ba..d6f305dc 100644 --- a/cobra/interface.go +++ b/cobra/interface.go @@ -82,7 +82,7 @@ type Cobra interface { AddCommand(subCmd ...*spfcbr.Command) AddCommandCompletion() - AddCommandConfigure(basename string, defaultConfig func() io.Reader) + AddCommandConfigure(alias, basename string, defaultConfig func() io.Reader) AddCommandPrintErrorCode(fct FuncPrintErrorCode) Execute() error