Simplify the parsing loop so that we don't try to find out the "$command" when looping over arguments initially, we'll only look for the --quiet and --cached options. Then if we have no more arguments we default to "status", otherwise we emit our usage info. Most importantly we don't need to give --cache to only "status" and "summary", instead we trust that "submodule--helper" is checking those arguments, if some subcommands don't them they can emit their own errors. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- git-submodule.sh | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index cad9948c047..0274b253297 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -29,50 +29,40 @@ cd_to_toplevel GIT_PROTOCOL_FROM_USER=0 export GIT_PROTOCOL_FROM_USER -command= quiet= cached= -while test $# != 0 && test -z "$command" +while test $# != 0 do case "$1" in - add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs) - command=$1 - ;; -q|--quiet) - quiet=1 + quiet=1 && + shift ;; --cached) - cached=1 - ;; - --) - break - ;; - -*) - usage + cached=1 && + shift ;; *) break ;; esac - shift done # No command word defaults to "status" -if test -z "$command" +command= +if test $# = 0 then - if test $# = 0 - then command=status - else - usage - fi -fi - -# "--cached" is accepted only by "status" and "summary" -if test -n "$cached" && test "$command" != status && test "$command" != summary -then - usage +else + case "$1" in + add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs) + command=$1 && + shift + ;; + *) + usage + esac fi case "$command" in @@ -83,7 +73,7 @@ update) git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ ${quiet:+--quiet} ${wt_prefix:+--prefix "$wt_prefix"} "$@" ;; -add | foreach | init | deinit | set-branch | set-url | status | summary | sync) +*) git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ ${quiet:+--quiet} ${cached:+--cached} "$@" ;; -- 2.36.1.1178.gb5b1747c546