From 3a835ebd611ca236e6a3791828589ecb601453dc Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 22 Nov 2018 12:43:35 +0100 Subject: [PATCH] Make --help work See #5361. --- share/functions/funced.fish | 7 ++++++- share/functions/funcsave.fish | 7 ++++++- share/functions/open.fish | 7 ++++++- share/functions/realpath.fish | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/share/functions/funced.fish b/share/functions/funced.fish index f4a53235e..8723a0ccb 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -13,7 +13,7 @@ end function funced --description 'Edit function definition' set -l options 'h/help' 'e/editor=' 'i/interactive' 's/save' - argparse -n funced --min-args=1 --max-args=1 $options -- $argv + argparse -n funced --max-args=1 $options -- $argv or return if set -q _flag_help @@ -21,6 +21,11 @@ function funced --description 'Edit function definition' return 0 end + if not set -q argv[1] + printf (_ "%ls: Expected at least %d args, got only %d\n") funced 1 0 + return 1 + end + set funcname $argv[1] # Check VISUAL first since theoretically EDITOR could be ed. diff --git a/share/functions/funcsave.fish b/share/functions/funcsave.fish index fedf80392..31b553fbd 100644 --- a/share/functions/funcsave.fish +++ b/share/functions/funcsave.fish @@ -1,6 +1,6 @@ function funcsave --description "Save the current definition of all specified functions to file" set -l options 'h/help' - argparse -n funcsave --min-args=1 $options -- $argv + argparse -n funcsave $options -- $argv or return if set -q _flag_help @@ -8,6 +8,11 @@ function funcsave --description "Save the current definition of all specified fu return 0 end + if not set -q argv[1] + printf (_ "%ls: Expected at least %d args, got only %d\n") funcsave 1 0 + return 1 + end + if not mkdir -p $__fish_config_dir/functions printf (_ "%s: Could not create configuration directory\n") funcsave return 1 diff --git a/share/functions/open.fish b/share/functions/open.fish index a4fce0918..2848e6faa 100644 --- a/share/functions/open.fish +++ b/share/functions/open.fish @@ -5,7 +5,7 @@ if not command -sq open function open --description "Open file in default application" set -l options 'h/help' - argparse -n open --min-args=1 $options -- $argv + argparse -n open $options -- $argv or return if set -q _flag_help @@ -13,6 +13,11 @@ if not command -sq open return 0 end + if not set -q argv[1] + printf (_ "%ls: Expected at least %d args, got only %d\n") open 1 0 + return 1 + end + if type -q -f cygstart for i in $argv cygstart $i diff --git a/share/functions/realpath.fish b/share/functions/realpath.fish index 4ae3b15c8..3b0881cc7 100644 --- a/share/functions/realpath.fish +++ b/share/functions/realpath.fish @@ -25,7 +25,7 @@ function realpath -d "return an absolute path without symlinks" set -l options 'h/help' 'q/quiet' 'V-version' 's/strip' 'N-no-symlinks' 'z/zero' set -a options 'e/canonicalize-existing' 'm/canonicalize-missing' 'L/logical' 'P/physical' set -a options 'R-relative-to=' 'B-relative-base=' - argparse -n realpath --min-args=1 $options -- $argv + argparse -n realpath $options -- $argv or return if set -q _flag_help @@ -42,6 +42,11 @@ function realpath -d "return an absolute path without symlinks" return 1 end + if not set -q argv[1] + printf (_ "%ls: Expected at least %d args, got only %d\n") realpath 1 0 + return 1 + end + for path in $argv builtin realpath $path end