From: Jonas Fonseca <fonseca@diku.dk>
To: Petr Baudis <pasky@ucw.cz>
Cc: git@vger.kernel.org
Subject: [PATCH] Convert commands to optparse
Date: Sat, 11 Jun 2005 03:52:11 +0200 [thread overview]
Message-ID: <20050611015211.GB13272@diku.dk> (raw)
Convert all remaining commands providing options to optparse.
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
Tested lightly ...
cg-admin-ls | 15 +++++++++------
cg-admin-uncommit | 11 +++++++----
cg-clone | 16 ++++++++++------
cg-commit | 30 +++++++++++-------------------
cg-merge | 23 +++++++++++------------
cg-pull | 14 ++++++++------
cg-update | 13 ++++++++-----
7 files changed, 64 insertions(+), 58 deletions(-)
diff --git a/cg-admin-ls b/cg-admin-ls
--- a/cg-admin-ls
+++ b/cg-admin-ls
@@ -34,11 +34,14 @@ USAGE="cg-admin-ls [-t TREE_ID] [PATH]"
. ${COGITO_LIB}cg-Xlib
tree_id=
-if [ "$1" = "-t" ]; then
- shift
- tree_id=$1
- shift
-fi
+while optparse; do
+ if optparse -t=; then
+ tree_id="$OPTARG"
+ else
+ optfail
+ fi
+done
+
id=$(tree-id $tree_id) || exit 1
-git-ls-tree "$id" "$@"
+git-ls-tree "$id" "${ARGS[@]}"
diff --git a/cg-admin-uncommit b/cg-admin-uncommit
--- a/cg-admin-uncommit
+++ b/cg-admin-uncommit
@@ -24,10 +24,13 @@ USAGE="cg-admin-uncommit [-t] [COMMIT_ID
[ -s $_git/blocked ] && die "uncommitting blocked: $(cat $_git/blocked)"
rollback_tree=
-if [ "$1" = "-t" ]; then
- shift
- rollback_tree=1
-fi
+while optparse; do
+ if optparse -t; then
+ rollback_tree=1
+ else
+ optfail
+ fi
+done
base=$(commit-id) || exit 1
diff --git a/cg-clone b/cg-clone
--- a/cg-clone
+++ b/cg-clone
@@ -23,16 +23,20 @@ _git_repo_unneeded=1
. ${COGITO_LIB}cg-Xlib
same_dir=
-if [ "$1" = "-s" ]; then
- shift
- same_dir=1
-fi
+while optparse; do
+ if optparse -s; then
+ same_dir=1
+ else
+ optfail
+ fi
+done
+
+location=${ARGS[0]}
-location=$1
[ "$location" ] || usage
location=${location%/}
-destdir=$2
+destdir=${ARGS[1]}
if [ "$destdir" ]; then
[ ! "$same_dir" ] || die "specifying both -s and DESTDIR makes no sense"
dir=$destdir
diff --git a/cg-commit b/cg-commit
--- a/cg-commit
+++ b/cg-commit
@@ -83,34 +83,26 @@ forceeditor=
ignorecache=
commitalways=
msgs=()
-while [ "$1" ]; do
- case "$1" in
- -C)
+while optparse; do
+ if optparse -C; then
ignorecache=1
- shift
- ;;
- -e)
+ elif optparse -e; then
forceeditor=1
- shift
- ;;
- -E)
+ elif optparse -E; then
forceeditor=1
commitalways=1
- shift
- ;;
- -m*)
- msgs=("${msgs[@]}" "${1#-m}")
- shift
- ;;
- *) break;;
- esac
+ elif optparse -m=; then
+ msgs=("${msgs[@]}" "$OPTARG")
+ else
+ optfail
+ fi
done
-if [ "$1" ]; then
+if [ "$ARGS" ]; then
[ "$ignorecache" ] && die "-C and listing files to commit does not make sense"
[ -s $_git/merging ] && die "cannot commit individual files when merging"
- eval commitfiles=($(git-diff-cache -r -m HEAD -- "$@" | \
+ eval commitfiles=($(git-diff-cache -r -m HEAD -- "${ARGS[@]}" | \
sed 's/^\([^ ]*\)\(. .*\)\( .*\)*$/"\2"/'))
customfiles=1
diff --git a/cg-merge b/cg-merge
--- a/cg-merge
+++ b/cg-merge
@@ -27,20 +27,19 @@ head=$(commit-id)
careful=
-if [ "$1" = "-c" ]; then
- shift
- careful=1
-fi
-
base=
-if [ "$1" = "-b" ]; then
- shift
- [ "$1" ] || usage
- base=$(commit-id "$1") || exit 1; shift
-fi
+while optparse; do
+ if optparse -c; then
+ careful=1
+ elif optparse -b=; then
+ base=$(commit-id "$OPTARG") || exit 1
+ else
+ optfail
+ fi
+done
-[ "$1" ] || usage
-branchname="$1"
+[ "$ARGS" ] || usage
+branchname="${ARGS[0]}"
branch=$(commit-id "$branchname") || exit 1
[ "$base" ] || base=$(git-merge-base "$head" "$branch")
diff --git a/cg-pull b/cg-pull
--- a/cg-pull
+++ b/cg-pull
@@ -17,13 +17,15 @@ USAGE="cg-pull [-f] [BRANCH_NAME]"
. ${COGITO_LIB}cg-Xlib
force=
-if [ "$1" = "-f" ]; then
- force=1
- shift
-fi
-
-name=$1
+while optparse; do
+ if optparse -f; then
+ force=1
+ else
+ optfail
+ fi
+done
+name=${ARGS[0]}
[ "$name" ] || { [ -s $_git/refs/heads/origin ] && name=origin; }
[ "$name" ] || die "where to pull from?"
diff --git a/cg-update b/cg-update
--- a/cg-update
+++ b/cg-update
@@ -18,12 +18,15 @@ USAGE="cg-update [-f] [BRANCH_NAME]"
. ${COGITO_LIB}cg-Xlib
force=
-if [ "$1" = "-f" ]; then
- force=$1
- shift
-fi
+while optparse; do
+ if optparse -f; then
+ force=-f
+ else
+ optfail
+ fi
+done
-name=$1
+name=${ARGS[0]}
[ "$name" ] || { [ -s $_git/refs/heads/origin ] && name=origin; }
[ "$name" ] || die "where to update from?"
--
Jonas Fonseca
reply other threads:[~2005-06-11 1:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20050611015211.GB13272@diku.dk \
--to=fonseca@diku.dk \
--cc=git@vger.kernel.org \
--cc=pasky@ucw.cz \
/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