|
|
|
@ -64,25 +64,22 @@ func (a *App) writeFishCompletionTemplate(w io.Writer) error {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) prepareFishCommands(
|
|
|
|
|
commands []Command,
|
|
|
|
|
allCommands *[]string,
|
|
|
|
|
previousCommands []string,
|
|
|
|
|
) []string {
|
|
|
|
|
func (a *App) prepareFishCommands(commands []Command, allCommands *[]string, previousCommands []string) []string {
|
|
|
|
|
completions := []string{}
|
|
|
|
|
for i := range commands {
|
|
|
|
|
command := &commands[i]
|
|
|
|
|
|
|
|
|
|
var completion strings.Builder
|
|
|
|
|
completion.WriteString(fmt.Sprintf(
|
|
|
|
|
"complete -c %s -f -n '%s' -a '%s'",
|
|
|
|
|
"complete -r -c %s -n '%s' -a '%s'",
|
|
|
|
|
a.Name,
|
|
|
|
|
a.fishSubcommandHelper(previousCommands),
|
|
|
|
|
strings.Join(command.Names(), " "),
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
if command.Usage != "" {
|
|
|
|
|
completion.WriteString(fmt.Sprintf(" -d '%s'", command.Usage))
|
|
|
|
|
completion.WriteString(fmt.Sprintf(" -d '%s'",
|
|
|
|
|
escapeSingleQuotes(command.Usage)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !command.HideHelp {
|
|
|
|
@ -113,10 +110,7 @@ func (a *App) prepareFishCommands(
|
|
|
|
|
return completions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) prepareFishFlags(
|
|
|
|
|
flags []Flag,
|
|
|
|
|
previousCommands []string,
|
|
|
|
|
) []string {
|
|
|
|
|
func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string {
|
|
|
|
|
completions := []string{}
|
|
|
|
|
for _, f := range flags {
|
|
|
|
|
flag, ok := f.(DocGenerationFlag)
|
|
|
|
@ -124,13 +118,15 @@ func (a *App) prepareFishFlags(
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var completion strings.Builder
|
|
|
|
|
completion := &strings.Builder{}
|
|
|
|
|
completion.WriteString(fmt.Sprintf(
|
|
|
|
|
"complete -c %s -f -n '%s'",
|
|
|
|
|
"complete -c %s -n '%s'",
|
|
|
|
|
a.Name,
|
|
|
|
|
a.fishSubcommandHelper(previousCommands),
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
fishAddFileFlag(f, completion)
|
|
|
|
|
|
|
|
|
|
for idx, opt := range strings.Split(flag.GetName(), ",") {
|
|
|
|
|
if idx == 0 {
|
|
|
|
|
completion.WriteString(fmt.Sprintf(
|
|
|
|
@ -149,7 +145,8 @@ func (a *App) prepareFishFlags(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if flag.GetUsage() != "" {
|
|
|
|
|
completion.WriteString(fmt.Sprintf(" -d '%s'", flag.GetUsage()))
|
|
|
|
|
completion.WriteString(fmt.Sprintf(" -d '%s'",
|
|
|
|
|
escapeSingleQuotes(flag.GetUsage())))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
completions = append(completions, completion.String())
|
|
|
|
@ -158,6 +155,24 @@ func (a *App) prepareFishFlags(
|
|
|
|
|
return completions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func fishAddFileFlag(flag Flag, completion *strings.Builder) {
|
|
|
|
|
switch f := flag.(type) {
|
|
|
|
|
case GenericFlag:
|
|
|
|
|
if f.TakesFile {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
case StringFlag:
|
|
|
|
|
if f.TakesFile {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
case StringSliceFlag:
|
|
|
|
|
if f.TakesFile {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
completion.WriteString(" -f")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) fishSubcommandHelper(allCommands []string) string {
|
|
|
|
|
fishHelper := fmt.Sprintf("__fish_%s_no_subcommand", a.Name)
|
|
|
|
|
if len(allCommands) > 0 {
|
|
|
|
@ -169,3 +184,7 @@ func (a *App) fishSubcommandHelper(allCommands []string) string {
|
|
|
|
|
return fishHelper
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func escapeSingleQuotes(input string) string {
|
|
|
|
|
return strings.Replace(input, `'`, `\'`, -1)
|
|
|
|
|
}
|
|
|
|
|