Skip to content

Commit

Permalink
make string ''\)\n' a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Jan 30, 2021
1 parent e0f2093 commit 66024f2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bash_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,15 @@ func writeFlagHandler(buf *bytes.Buffer, name string, annotations map[string][]s
}
}

const cbn = "\")\n"

func writeShortFlag(buf *bytes.Buffer, flag *pflag.Flag, cmd *Command) {
name := flag.Shorthand
format := " "
if len(flag.NoOptDefVal) == 0 {
format += "two_word_"
}
format += "flags+=(\"-%s\")\n"
format += "flags+=(\"-%s" + cbn
buf.WriteString(fmt.Sprintf(format, name))
writeFlagHandler(buf, "-"+name, flag.Annotations, cmd)
}
Expand All @@ -484,20 +486,20 @@ func writeFlag(buf *bytes.Buffer, flag *pflag.Flag, cmd *Command) {
if len(flag.NoOptDefVal) == 0 {
format += "="
}
format += "\")\n"
format += cbn
buf.WriteString(fmt.Sprintf(format, name))
if len(flag.NoOptDefVal) == 0 {
format = " two_word_flags+=(\"--%s\")\n"
format = " two_word_flags+=(\"--%s" + cbn
buf.WriteString(fmt.Sprintf(format, name))
}
writeFlagHandler(buf, "--"+name, flag.Annotations, cmd)
}

func writeLocalNonPersistentFlag(buf *bytes.Buffer, flag *pflag.Flag) {
name := flag.Name
format := " local_nonpersistent_flags+=(\"--%[1]s\")\n"
format := " local_nonpersistent_flags+=(\"--%[1]s" + cbn
if len(flag.NoOptDefVal) == 0 {
format += " local_nonpersistent_flags+=(\"--%[1]s=\")\n"
format += " local_nonpersistent_flags+=(\"--%[1]s=" + cbn
}
buf.WriteString(fmt.Sprintf(format, name))
if len(flag.Shorthand) > 0 {
Expand Down

0 comments on commit 66024f2

Please sign in to comment.