git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: imyousuf@gmail.com
To: git@vger.kernel.org
Cc: gitster@pobox.com, Imran M Yousuf <imyousuf@smartitengineering.com>
Subject: [PATCH] - Updated usage and simplified sub-command action invocation
Date: Thu, 10 Jan 2008 10:07:25 +0600	[thread overview]
Message-ID: <1199938045-16289-1-git-send-email-imyousuf@gmail.com> (raw)

From: Imran M Yousuf <imyousuf@smartitengineering.com>

- manual page of git-submodule and usage mentioned in git-subcommand.sh
were not same, thus synchronized them. In doing so also had to change the
way the subcommands were parsed.

- Previous version did not allow commands such as "git-submodule add init
update". Thus not satisfying the following case -

mkdir g; mkdir f; cd g/
touch g.txt; echo "sample text for g.txt" >> ./g.txt; git-init;
git-add g.txt; git-commit -a -m "First commit on g"
cd ../f/; ln -s ../g/ init
git-init; git-submodule add init update;
git-commit -a -m "With module update"
mkdir ../test; cd ../test
git-clone ../f/; cd f
git-submodule init update; git-submodule update update
cd ../..; rm -rf ./f/ ./test/ ./g/

This patch fixes this issue and allows it as well.

- Added 2 specific messages for usage error related to branch and cached

- Simplified subcommand action invocation by simply invoking the action if
all conditions are fulfilled. Excepting for parsing command line arguments
case statements are avoided and instead more direct if statement is
introduced.

Signed-off-by: Imran M Yousuf <imyousuf@smartitengineering.com>
---
 git-submodule.sh |   97 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 65 insertions(+), 32 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index ad9fe62..5d5e41d 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -4,18 +4,23 @@
 #
 # Copyright (c) 2007 Lars Hjemli
 
-USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'
+# Synopsis of this commands are as follows
+# git-submodule [--quiet] [-b branch] add <repository> [<path>]
+# git-submodule [--quiet] [--cached] [status] [--] [<path>...]
+# git-submodule [--quiet] init [--] [<path>...]
+# git-submodule [--quiet] update [--] [<path>...]
+USAGE='[--quiet] [[[[-b branch] add <repo>]|[[[[--cached] status]|init|update] [--]]]  [<path>...]]'
 OPTIONS_SPEC=
 . git-sh-setup
 require_work_tree
 
+MODULES_LIST='modules_list'
+
 add=
 branch=
-init=
-update=
-status=
 quiet=
 cached=
+command=
 
 #
 # print stuff on stdout unless -q was specified
@@ -293,20 +298,47 @@ modules_list()
 	done
 }
 
+# If there is '--' as the first argument simply ignores it and thus shifts
+check_for_terminator()
+{
+	if test -n "$1" && test "$1" = "--"
+	then
+		shift
+	fi
+}
+
+# Command synopsis clearly shows that all arguments after
+# subcommand are arguments to the command itself. Thus
+# there lies no command that has configuration argument
+# after the mention of the subcommand. Thus once the
+# subcommand is found and the separator ('--') is ignored
+# rest can be safely sent the subcommand action
 while test $# != 0
 do
 	case "$1" in
 	add)
 		add=1
+		command="module_$1"
+		shift
+		break
 		;;
 	init)
-		init=1
+		command="modules_$1"
+		shift
+		check_for_terminator "$1"
+		break
 		;;
 	update)
-		update=1
+		command="modules_$1"
+		shift
+		check_for_terminator "$1"
+		break
 		;;
 	status)
-		status=1
+		command="$MODULES_LIST"
+		shift
+		check_for_terminator "$1";
+		break
 		;;
 	-q|--quiet)
 		quiet=1
@@ -323,6 +355,9 @@ do
 		cached=1
 		;;
 	--)
+		# It is shifted so that it is not passed
+		# as an argument to the default subcommand
+		shift
 		break
 		;;
 	-*)
@@ -335,30 +370,28 @@ do
 	shift
 done
 
-case "$add,$branch" in
-1,*)
-	;;
-,)
-	;;
-,*)
+# Throws usage error if branch is not used with add command
+if test -n "$branch" &&
+   test -z "$add"
+then
+	echo Branch can not be specified without add subcommand
 	usage
-	;;
-esac
-
-case "$add,$init,$update,$status,$cached" in
-1,,,,)
-	module_add "$@"
-	;;
-,1,,,)
-	modules_init "$@"
-	;;
-,,1,,)
-	modules_update "$@"
-	;;
-,,,*,*)
-	modules_list "$@"
-	;;
-*)
+fi
+
+# If no command is specified than default command
+# is - git submodule status
+if test -z "$command"
+then
+	command="$MODULES_LIST"
+fi
+
+# Throws usage if --cached is used by other than status, init or update
+# that is used with add command
+if test -n "$cached" &&
+   test "$command" != "$MODULES_LIST"
+then
+	echo Cached can only be used with the status subcommand
 	usage
-	;;
-esac
+fi
+
+"$command" "$@"
-- 
1.5.3.7

             reply	other threads:[~2008-01-10  4:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-10  4:07 imyousuf [this message]
2008-01-10  6:23 ` [PATCH] - Updated usage and simplified sub-command action invocation Junio C Hamano
2008-01-10  6:51   ` Imran M Yousuf
2008-01-10  7:22     ` Junio C Hamano
2008-01-10  7:41       ` Imran M Yousuf
2008-01-12  1:38         ` Junio C Hamano
2008-01-11  9:09   ` Imran M Yousuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1199938045-16289-1-git-send-email-imyousuf@gmail.com \
    --to=imyousuf@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=imyousuf@smartitengineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).