]> git.tuebingen.mpg.de Git - gsu.git/commitdiff
subcommand: Fix and document return value of gsu_complete_options().
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 17 Apr 2017 14:19:38 +0000 (16:19 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 30 Nov 2017 09:39:46 +0000 (10:39 +0100)
The value returned in $ret was undocumented so far. And it did not
make sense either: We used to return 0 if the current word does not
start with a hyphen, and the number of options in the given optstring
otherwise. Hence the value of zero is ambiguous.

Nobody needs the number of options anyway, so let's simply return 0
or 1, and document this.

subcommand

index a07f4145c69adb6fa319dbdaa9c97e3b0a2d5cde..956fb5c865ad3ae780ac7344917345879380aa8e 100644 (file)
@@ -187,6 +187,8 @@ _gsu_print_available_commands()
 
 # Print all options of the given optstring to stdout if the word in the current
 # command line begins with a hyphen character.
 
 # Print all options of the given optstring to stdout if the word in the current
 # command line begins with a hyphen character.
+#
+# Returns 0 if the current word does not start with a hyphen, one otherwise.
 gsu_complete_options()
 {
        local opts="$1" cword="$2" cur opt
 gsu_complete_options()
 {
        local opts="$1" cword="$2" cur opt
@@ -198,13 +200,12 @@ gsu_complete_options()
        ret=0
        [[ ! "$cur" == -* ]] && return
 
        ret=0
        [[ ! "$cur" == -* ]] && return
 
-       ret=0
        for ((i=0; i < ${#opts}; i++)); do
                opt="${opts:$i:1}"
                [[ "$opt" == ":" ]] && continue
                printf "%s" "-$opt "
        for ((i=0; i < ${#opts}; i++)); do
                opt="${opts:$i:1}"
                [[ "$opt" == ":" ]] && continue
                printf "%s" "-$opt "
-               let ret++
        done
        done
+       ret=1
 }
 
 com_prefs_options='e'
 }
 
 com_prefs_options='e'