Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ func fishSubcommandHelper(binary string, command *Command, siblings []*Command)
for _, sibling := range siblings {
siblingNames = append(siblingNames, sibling.Names()...)
}
ancestry := commandAncestry(command)
fishHelper = fmt.Sprintf(
"__fish_seen_subcommand_from %s; and not __fish_seen_subcommand_from %s",
strings.Join(command.Names(), " "),
"%s; and not __fish_seen_subcommand_from %s",
ancestry,
strings.Join(siblingNames, " "),
)
}
Expand All @@ -163,14 +164,26 @@ func fishSubcommandHelper(binary string, command *Command, siblings []*Command)
func fishFlagHelper(binary string, command *Command) string {
fishHelper := fmt.Sprintf("__fish_%s_no_subcommand", binary)
if len(command.Lineage()) > 1 {
fishHelper = fmt.Sprintf(
"__fish_seen_subcommand_from %s",
strings.Join(command.Names(), " "),
)
fishHelper = commandAncestry(command)
}
return fishHelper
}

func commandAncestry(command *Command) string {
var ancestry []string
ancestors := command.Lineage()
for i := len(ancestors) - 2; i >= 0; i-- {
ancestry = append(
ancestry,
fmt.Sprintf(
"__fish_seen_subcommand_from %s",
strings.Join(ancestors[i].Names(), " "),
),
)
}
return strings.Join(ancestry, "; and ")
}

func escapeSingleQuotes(input string) string {
return strings.ReplaceAll(input, `'`, `\'`)
}
14 changes: 7 additions & 7 deletions testdata/expected-fish-full.fish
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ complete -c greet -n '__fish_seen_subcommand_from config c' -l flag -s fl -s f -
complete -c greet -n '__fish_seen_subcommand_from config c' -f -l another-flag -s b -d 'another usage text'
complete -c greet -n '__fish_seen_subcommand_from config c' -f -l help -s h -d 'show help'
complete -x -c greet -n '__fish_seen_subcommand_from config c; and not __fish_seen_subcommand_from sub-config s ss help h' -a 'sub-config' -d 'another usage test'
complete -c greet -n '__fish_seen_subcommand_from sub-config s ss' -f -l sub-flag -s sub-fl -s s -r
complete -c greet -n '__fish_seen_subcommand_from sub-config s ss' -f -l sub-command-flag -s s -d 'some usage text'
complete -c greet -n '__fish_seen_subcommand_from sub-config s ss' -f -l help -s h -d 'show help'
complete -x -c greet -n '__fish_seen_subcommand_from sub-config s ss; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'
complete -c greet -n '__fish_seen_subcommand_from config c; and __fish_seen_subcommand_from sub-config s ss' -f -l sub-flag -s sub-fl -s s -r
complete -c greet -n '__fish_seen_subcommand_from config c; and __fish_seen_subcommand_from sub-config s ss' -f -l sub-command-flag -s s -d 'some usage text'
complete -c greet -n '__fish_seen_subcommand_from config c; and __fish_seen_subcommand_from sub-config s ss' -f -l help -s h -d 'show help'
complete -x -c greet -n '__fish_seen_subcommand_from config c; and __fish_seen_subcommand_from sub-config s ss; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'
complete -x -c greet -n '__fish_seen_subcommand_from config c; and not __fish_seen_subcommand_from sub-config s ss help h' -a 'help' -d 'Shows a list of commands or help for one command'
complete -x -c greet -n '__fish_greet_no_subcommand' -a 'info' -d 'retrieve generic information'
complete -c greet -n '__fish_seen_subcommand_from info i in' -f -l help -s h -d 'show help'
Expand All @@ -38,7 +38,7 @@ complete -c greet -n '__fish_seen_subcommand_from usage u' -l flag -s fl -s f -r
complete -c greet -n '__fish_seen_subcommand_from usage u' -f -l another-flag -s b -d 'another usage text'
complete -c greet -n '__fish_seen_subcommand_from usage u' -f -l help -s h -d 'show help'
complete -x -c greet -n '__fish_seen_subcommand_from usage u; and not __fish_seen_subcommand_from sub-usage su help h' -a 'sub-usage' -d 'standard usage text'
complete -c greet -n '__fish_seen_subcommand_from sub-usage su' -f -l sub-command-flag -s s -d 'some usage text'
complete -c greet -n '__fish_seen_subcommand_from sub-usage su' -f -l help -s h -d 'show help'
complete -x -c greet -n '__fish_seen_subcommand_from sub-usage su; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'
complete -c greet -n '__fish_seen_subcommand_from usage u; and __fish_seen_subcommand_from sub-usage su' -f -l sub-command-flag -s s -d 'some usage text'
complete -c greet -n '__fish_seen_subcommand_from usage u; and __fish_seen_subcommand_from sub-usage su' -f -l help -s h -d 'show help'
complete -x -c greet -n '__fish_seen_subcommand_from usage u; and __fish_seen_subcommand_from sub-usage su; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'
complete -x -c greet -n '__fish_seen_subcommand_from usage u; and not __fish_seen_subcommand_from sub-usage su help h' -a 'help' -d 'Shows a list of commands or help for one command'