Completions: Generalize function to add options
We add the function `__fish_kdb_add_option`, which adds suggestions for
a certain option to multiple `kdb` subcommands.
@@ -48,14 +48,6 @@ function __fish_kdb_needs_namespace -d 'Check if the current command needs a nam
return 0
end
-function __fish_kdb_option_verbose -d 'Check if the current command allows the option verbose'
- set subcommand (__fish_kdb_subcommand)
- contains -- "$subcommand" export file getmeta global-mount gmount info mount qt-gui remount rm sget shell test vset help
- and return 1
-
- not __input_includes '-v' '--verbose'
-end
-
function __fish_kdb_print_subcommands -d 'Print a list of kdb subcommands'
set -l commands (kdb list-commands $argv)
if contains -- $argv -v
@@ -69,6 +61,22 @@ function __fish_kdb_print_namespaces -d 'Print a list of possible namespace comp
kdb complete --max-depth=1 "$namespace" | string match -vr '(dir|proc|spec|user)$'
end
+function __fish_kdb_add_option -d 'Add suggestions for a certain option to multiple kdb subcommands'
+ set -l completion_function $argv[1]
+ set -l opt_long $argv[2]
+ set -l opt_short $argv[3]
+ set -l description $argv[4..-1]
+
+ set completion_function "$completion_function; and not __input_includes --$opt_long -$opt_short"
+
+ complete -c kdb -n "$completion_function" -l $opt_long -s $opt_short -d "$description"
+end
+
+function __fish_kdb_subcommand_option_verbose -d 'Check if the current subcommand supports the option verbose'
+ not __fish_kdb_subcommand_includes export file getmeta global-mount gmount info mount qt-gui remount rm sget shell test vset help qt-gui
+end
+end
+
# -- Completions ---------------------------------------------------------------------------------------------------------------------------
# =============
@@ -82,4 +90,4 @@ complete -c kdb -n '__fish_kdb_needs_namespace' -x -a '(__fish_kdb_print_namespa
# = Options =
# ===========
-complete -c kdb -n '__fish_kdb_option_verbose' -l 'verbose' -s 'v' -d 'Explain what is happening'
+__fish_kdb_add_option '__fish_kdb_subcommand_option_verbose' 'verbose' 'v' 'Explain what is happening'
