From: Andre Noll <maan@tuebingen.mpg.de>
Date: Mon, 17 Apr 2017 14:19:38 +0000 (+0200)
Subject: subcommand: Fix and document return value of gsu_complete_options().
X-Git-Url: https://git.tuebingen.mpg.de/?a=commitdiff_plain;h=46d356bc055978057542e999892ec6e0cf1c0153;p=gsu.git

subcommand: Fix and document return value of gsu_complete_options().

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.
---

diff --git a/subcommand b/subcommand
index a07f414..956fb5c 100644
--- a/subcommand
+++ b/subcommand
@@ -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.
+#
+# Returns 0 if the current word does not start with a hyphen, one otherwise.
 gsu_complete_options()
 {
 	local opts="$1" cword="$2" cur opt
@@ -198,13 +200,12 @@ gsu_complete_options()
 	ret=0
 	[[ ! "$cur" == -* ]] && return
 
-	ret=0
 	for ((i=0; i < ${#opts}; i++)); do
 		opt="${opts:$i:1}"
 		[[ "$opt" == ":" ]] && continue
 		printf "%s" "-$opt "
-		let ret++
 	done
+	ret=1
 }
 
 com_prefs_options='e'