mirror of
https://github.com/spf13/cobra
synced 2025-05-06 13:27:26 +00:00
initialize aliashash only when BASH_VERSION > 3
This commit is contained in:
parent
401e0bfc31
commit
376840c4f1
1 changed files with 11 additions and 4 deletions
|
@ -454,11 +454,18 @@ func writeRequiredNouns(buf *bytes.Buffer, cmd *Command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeCmdAliases(buf *bytes.Buffer, cmd *Command) {
|
func writeCmdAliases(buf *bytes.Buffer, cmd *Command) {
|
||||||
|
if len(cmd.Aliases) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sort.Sort(sort.StringSlice(cmd.Aliases))
|
sort.Sort(sort.StringSlice(cmd.Aliases))
|
||||||
|
|
||||||
|
buf.WriteString(fmt.Sprint(` if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then`, "\n"))
|
||||||
for _, value := range cmd.Aliases {
|
for _, value := range cmd.Aliases {
|
||||||
buf.WriteString(fmt.Sprintf(" command_aliases+=(%q)\n", value))
|
buf.WriteString(fmt.Sprintf(" command_aliases+=(%q)\n", value))
|
||||||
buf.WriteString(fmt.Sprintf(" aliashash[%q]=%q\n", value, cmd.Name()))
|
buf.WriteString(fmt.Sprintf(" aliashash[%q]=%q\n", value, cmd.Name()))
|
||||||
}
|
}
|
||||||
|
buf.WriteString(` fi`)
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
}
|
}
|
||||||
func writeArgAliases(buf *bytes.Buffer, cmd *Command) {
|
func writeArgAliases(buf *bytes.Buffer, cmd *Command) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue