threads / patch / 2794

patch, 25 partsgit-cherry: Print the usage message if we get an unknown option.

Subject: [PATCH 4/25] git-cherry: Print the usage message if we get an unknown option.

## tl;dr

34 messages between Dec 10, 2005 and Dec 11, 2005. Diffs are folded; open one to read it.

replies: 33people: 5as markdown or json

freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · lore

[PATCH 0/25] Usage message clean-up

This patch series is supposed to clean-up usage strings in *.sh and *.perl. I have gone through most of the scripts, but have left the following programs for various reasons.

No obvious fix:
  git-log.sh
  git-parse-remote.sh
  git-rebase.sh
Still todo:
  git-archimport.perl
  git-cvsexportcommit.perl
  git-cvsimport.perl
  git-svnimport.perl
  git-applymbox.sh
  git-applypatch.sh
  git-fmt-merge-msg.perl
  cmd-rename.sh
  git-ls-remote.sh
  git-merge-octopus.sh
  git-merge-one-file.sh
  git-merge-ours.sh
  git-merge-resolve.sh
  git-merge-stupid.sh
  git-octopus.sh
  git-parse-remote.sh
I have tried to follow the following rules:
* Any unrecognised options should make the script die with the usage
  message.
* -h and --help makes the script die with the usage message.
* The message is printed to stderr.
* The message is of the form "usage: $0 options"

I am not convinced that the last bullet point is the best way to do things. Using "$0" is probably best for Git developers but using "git program-name" is probably least confusing for users, especially if we are going to move the git-* binaries away from /usr/bin. Another option is "basename $0". What do you think?

--
 Documentation/git-revert.txt |    2 +
 git-bisect.sh                |    2 +
 git-branch.sh                |    2 +
 git-checkout.sh              |    2 +
 git-cherry.sh                |   18 ++++++++++--
 git-clone.sh                 |    2 +
 git-commit.sh                |    2 +
 git-count-objects.sh         |   11 +++++++
 git-fetch.sh                 |    8 +++++
 git-format-patch.sh          |    3 +-
 git-grep.sh                  |   11 ++++++-
 git-lost-found.sh            |   12 +++++++-
 git-merge.sh                 |    2 +
 git-mv.perl                  |   10 ++++++-
 git-prune.sh                 |    2 +
 git-pull.sh                  |    3 +-
 git-push.sh                  |    2 +
 git-relink.perl              |   10 +++----
 git-repack.sh                |    7 ++++-
 git-request-pull.sh          |    6 ++--
 git-reset.sh                 |    2 +
 git-revert.sh                |    4 +--
 git-send-email.perl          |   62 +++++++++++++++++++++++-------------------
 git-status.sh                |   12 +++++++-
 git-tag.sh                   |   10 +------
 git-verify-tag.sh            |   10 +++----
 26 files changed, 142 insertions(+), 75 deletions(-)
- Fredrik
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 1/25] git-bisect: Use $0 instead of program name in usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-bisect.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fdaaf0b14e5df17cbeef9e89ff85f33e3dcaa4d6
Show changes to git-bisect.sh +1 −1
diff --git a/git-bisect.sh b/git-bisect.sh
index 05dae8a..6ec35ab 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -12,7 +12,7 @@ sq() {
 }
 
 usage() {
-    echo >&2 'usage: git bisect [start|bad|good|next|reset|visualize]
+    echo >&2 'usage: $0 [start|bad|good|next|reset|visualize]
 git bisect start [<pathspec>]	reset bisect state and start bisection.
 git bisect bad [<rev>]		mark <rev> a known-bad revision.
 git bisect good [<rev>...]	mark <rev>... known-good revisions.
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore
Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-cherry.sh |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
10b829123619b4b3c398398726c830db87f7525a
Show changes to git-cherry.sh +15 −3
diff --git a/git-cherry.sh b/git-cherry.sh
index 867522b..c21cf65 100755
--- a/git-cherry.sh
+++ b/git-cherry.sh
@@ -5,7 +5,8 @@
 
 . git-sh-setup
 
-usage="usage: $0 "'[-v] <upstream> [<head>]
+usage () {
+    die "usage: $0 "'[-v] <upstream> [<head>]
 
              __*__*__*__*__> <upstream>
             /
@@ -18,8 +19,19 @@ compared against the change each commit 
 it is shown on the standard output with prefix "+".  Otherwise
 it is shown with prefix "-".
 '
+}
 
-case "$1" in -v) verbose=t; shift ;; esac 
+while [ "$#" != "0" ]; do
+    case "$1" in
+        "-v")
+            verbose=t;
+            shift
+            ;;
+        -*)
+            usage
+            ;;
+    esac
+done
 
 case "$#,$1" in
 1,*..*)
@@ -35,7 +47,7 @@ case "$#" in
 2) upstream=`git-rev-parse --verify "$1"` &&
    ours=`git-rev-parse --verify "$2"` || exit
    ;;
-*) echo >&2 "$usage"; exit 1 ;;
+*) usage ;;
 esac
 
 # Note that these list commits in reverse order;
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 2/25] git-branch: Use $0 instead of program name in usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-branch.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
57d5239afe20cda3f902d2deab4cd3777f82eca6
Show changes to git-branch.sh +1 −1
diff --git a/git-branch.sh b/git-branch.sh
index 5306b27..90a1b5b 100755
--- a/git-branch.sh
+++ b/git-branch.sh
@@ -8,7 +8,7 @@ die () {
 }
 
 usage () {
-    echo >&2 "usage: $(basename $0)"' [-d <branch>] | [[-f] <branch> [start-point]]
+    echo >&2 "usage: $0"' [-d <branch>] | [[-f] <branch> [start-point]]
 
 If no arguments, show available branches and mark current branch with a star.
 If one argument, create a new branch <branchname> based off of current HEAD.
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 3/25] git-checkout: Use $0 instead of program name in usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-checkout.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
480ea8310be08611c841ae428c57003ac48c1827
Show changes to git-checkout.sh +1 −1
diff --git a/git-checkout.sh b/git-checkout.sh
index 4cf30e2..2fcd766 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -2,7 +2,7 @@
 . git-sh-setup
 
 usage () {
-    die "usage: git checkout [-f] [-b <new_branch>] [<branch>] [<paths>...]"
+    die "usage: $0 [-f] [-b <new_branch>] [<branch>] [<paths>...]"
 }
 
 old=$(git-rev-parse HEAD)
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 9/25] git-format-patch: Use the 'die'-function where appropriate.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-format-patch.sh |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
78267845f0e0d20f23448692bf3ff967faf5fea7
Show changes to git-format-patch.sh +1 −2
diff --git a/git-format-patch.sh b/git-format-patch.sh
index 1eebe85..4ecbf49 100755
--- a/git-format-patch.sh
+++ b/git-format-patch.sh
@@ -10,7 +10,7 @@ LANG=C LC_ALL=C
 export LANG LC_ALL
 
 usage () {
-    echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox]
+    die "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox]
     [--check] [--signoff] [-<diff options>...]
     [--help]
     ( from..to ... | upstream [ our-head ] )
@@ -30,7 +30,6 @@ When --mbox is specified, the output is 
 UNIX mailbox format, and can be concatenated together for processing
 with applymbox.
 '
-    exit 1
 }
 
 diff_opts=
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 6/25] git-commit: Use $0 instead of program name in usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-commit.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
2b859132aeae56504c0d7aaa99436dce9dac2117
Show changes to git-commit.sh +1 −1
diff --git a/git-commit.sh b/git-commit.sh
index 3d250ec..1893f98 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -6,7 +6,7 @@
 . git-sh-setup
 
 usage () {
-	die 'git commit [-a] [-s] [-v | --no-verify]  [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
+	die "usage: $0 [-a] [-s] [-v | --no-verify]  [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]"
 }
 
 all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 5/25] git-clone: Use $0 instead of program name in usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-clone.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
028cbc161562fae23c9797564c8d50da6c082941
Show changes to git-clone.sh +1 −1
diff --git a/git-clone.sh b/git-clone.sh
index 699205e..d07e4d9 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -9,7 +9,7 @@
 unset CDPATH
 
 usage() {
-	echo >&2 "* git clone [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
+	echo >&2 "usage: $0 [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
 	exit 1
 }
 
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 7/25] git-count-objects: Die with usage message if we are invoked incorrectly.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-count-objects.sh |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
5db708396a841860c4d5e41c2acd60476d2207c4
Show changes to git-count-objects.sh +10 −1
diff --git a/git-count-objects.sh b/git-count-objects.sh
index 40c58ef..0d544ad 100755
--- a/git-count-objects.sh
+++ b/git-count-objects.sh
@@ -3,7 +3,16 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
+. git-sh-setup
+
+usage () {
+    die "usage: $0"
+}
+
+if [ "$#" != "0" ]
+then
+    usage
+fi
 
 dc </dev/null 2>/dev/null || {
 	# This is not a real DC at all -- it just knows how
-- 
0.99.9.GIT
Junio C Hamano· Dec 11, 2005, 04:22 UTC · re: freku045@student.liu.se · lore

Re: [PATCH 7/25] git-count-objects: Die with usage message if we are invoked incorrectly.

freku045@student.liu.se writes:
Show 11 quoted lines
> 5db708396a841860c4d5e41c2acd60476d2207c4
> diff --git a/git-count-objects.sh b/git-count-objects.sh
> index 40c58ef..0d544ad 100755
> --- a/git-count-objects.sh
> +++ b/git-count-objects.sh
> @@ -3,7 +3,16 @@
>  # Copyright (c) 2005 Junio C Hamano
>  #
>  
> -GIT_DIR=`git-rev-parse --git-dir` || exit $?
> +. git-sh-setup

Not that it matters too much, but this makes count-object not work from subdirectory.

freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 8/25] git-fetch: Print usage message if we get an unrecognized option.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-fetch.sh |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
50d509080e5cf32880bf412133473557f9e5f5b2
Show changes to git-fetch.sh +8 −0
diff --git a/git-fetch.sh b/git-fetch.sh
index 14ea295..18b421d 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -2,6 +2,11 @@
 #
 . git-sh-setup
 . git-parse-remote
+
+usage () {
+    die "usage: $0 <fetch-options> <repository> <refspec>..."
+}
+
 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
 
@@ -34,6 +39,9 @@ do
 	-v|--verbose)
 		verbose=Yes
 		;;
+        -*)
+                usage
+                ;;
 	*)
 		break
 		;;
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 10/25] git-grep: Print usage message on '-h' and '--help'.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-grep.sh |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
b375c3ad7c6ce4d6cda208c61828f8ff72cb7d53
Show changes to git-grep.sh +9 −2
diff --git a/git-grep.sh b/git-grep.sh
index 44c1613..e6acc41 100755
--- a/git-grep.sh
+++ b/git-grep.sh
@@ -3,6 +3,11 @@
 # Copyright (c) Linus Torvalds, 2005
 #
 
+usage () {
+        echo >&2 "usage: $0 <option>... <pattern> [pathspec*]"
+        exit 1
+}
+
 pattern=
 flags=()
 git_flags=()
@@ -26,6 +31,9 @@ while : ; do
 		shift
 		break
 		;;
+        -h|--h|--he|--hel|--help)
+                usage
+                ;;
 	-*)
 		flags=("${flags[@]}" "$1")
 		;;
@@ -40,8 +48,7 @@ while : ; do
 	shift
 done
 [ "$pattern" ] || {
-	echo >&2 "usage: 'git grep <pattern> [pathspec*]'"
-	exit 1
+        usage
 }
 git-ls-files -z "${git_flags[@]}" "$@" |
 	xargs -0 grep "${flags[@]}" -e "$pattern"
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 16/25] git-push: Clean up usage message

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-push.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
81b8c434e68712e5309af3d573cf13ebcb911a6f
Show changes to git-push.sh +1 −1
diff --git a/git-push.sh b/git-push.sh
index 140c8f8..3336312 100755
--- a/git-push.sh
+++ b/git-push.sh
@@ -2,7 +2,7 @@
 . git-sh-setup
 
 usage () {
-    die "Usage: git push [--all] [--force] <repository> [<refspec>]"
+    die "usage: git push [--all] [--force] <repository> [<refspec>...]"
 }
 
 
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 15/25] git-pull: Don't print an extra new line at the end of the usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-pull.sh |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
6123ce84502e443c10c6689966aa51c821775a1a
Show changes to git-pull.sh +1 −2
diff --git a/git-pull.sh b/git-pull.sh
index 3a13984..5a1ae2c 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -12,8 +12,7 @@ usage () {
     [<fetch-options>]
     <repo> <head>...
 
-Fetch one or more remote refs and merge it/them into the current HEAD.
-'
+Fetch one or more remote refs and merge it/them into the current HEAD.'
     exit 1
 }
 
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 13/25] git-merge: Print $0 instead of program name in usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-merge.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
ea22e6b3b15294ae1c6f367b109ee3f969b115c8
Show changes to git-merge.sh +1 −1
diff --git a/git-merge.sh b/git-merge.sh
index a221daa..f7aca19 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -9,7 +9,7 @@ LF='
 '
 
 usage () {
-    die "git-merge [-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+"
+    die "usage: $0 [-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+"
 }
 
 all_strategies='recursive octopus resolve stupid ours'
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 16/25] git-push: Clean-up usage message

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-push.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
81b8c434e68712e5309af3d573cf13ebcb911a6f
Show changes to git-push.sh +1 −1
diff --git a/git-push.sh b/git-push.sh
index 140c8f8..3336312 100755
--- a/git-push.sh
+++ b/git-push.sh
@@ -2,7 +2,7 @@
 . git-sh-setup
 
 usage () {
-    die "Usage: git push [--all] [--force] <repository> [<refspec>]"
+    die "usage: $0 [--all] [--force] <repository> [<refspec>...]"
 }
 
 
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 14/25] git-prune: Print $0 instead of program name in usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-prune.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
9c6661f08f42a6a1c76e43749d6e455bd1237dcb
Show changes to git-prune.sh +1 −1
diff --git a/git-prune.sh b/git-prune.sh
index 7e7f0ad..289aca0 100755
--- a/git-prune.sh
+++ b/git-prune.sh
@@ -9,7 +9,7 @@ do
     case "$1" in
     -n) dryrun=-n echo=echo ;;
     --) break ;;
-    -*) echo >&2 "usage: git-prune [ -n ] [ heads... ]"; exit 1 ;;
+    -*) echo >&2 "usage: $0 [-n] [--] [<head>...]"; exit 1 ;;
     *)  break ;;
     esac
     shift;
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 11/25] git-revert: Fix usage message

Also syncs the usage message in the documentation with the usage message in the implementation.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 Documentation/git-revert.txt |    2 +-
 git-revert.sh                |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
3fbfe1e03eba7db1e484b7d00ac77820e6a11907
Show changes to 2 files +3 −3

Documentation/git-revert.txt, git-revert.sh

diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
index e27c680..6684a60 100644
--- a/Documentation/git-revert.txt
+++ b/Documentation/git-revert.txt
@@ -7,7 +7,7 @@ git-revert - Revert an existing commit.
 
 SYNOPSIS
 --------
-'git-revert' [--edit | --no-edit] [-n] <commit>
+'git-revert' [--edit | --no-edit] [-n | --no-commit] <commit>
 
 DESCRIPTION
 -----------
diff --git a/git-revert.sh b/git-revert.sh
index 9d499c4..0a94344 100755
--- a/git-revert.sh
+++ b/git-revert.sh
@@ -19,10 +19,10 @@ esac
 usage () {
 	case "$me" in
 	cherry-pick)
-		die "usage git $me [--edit] [-n] [-r] <commit-ish>"
+		die "usage: $0 [--edit] [-n | --no-commit] [-r] <commit>"
 		;;
 	revert)
-		die "usage git $me [--edit | --no-edit] [-n] <commit-ish>"
+		die "usage $0 [--edit | --no-edit] [-n | --no-commit] <commit>"
 		;;
 	esac
 }
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 12/25] git-lost-found: Print usage message on incorrect invocation.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-lost-found.sh |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
2b2c389a8816f40cfa5b562203988b0c0b2269c5
Show changes to git-lost-found.sh +11 −1
diff --git a/git-lost-found.sh b/git-lost-found.sh
index 2beec2a..757e51f 100755
--- a/git-lost-found.sh
+++ b/git-lost-found.sh
@@ -1,6 +1,16 @@
 #!/bin/sh
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
+. git-sh-setup
+
+usage () {
+	die "usage: $0"
+}
+
+if [ "$#" != "0" ]
+then
+    usage
+fi
+
 laf="$GIT_DIR/lost-found"
 rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit
 
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 19/25] git-request-pull: Print usage message to stderr.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-request-pull.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
342b45c20724b86b1b12c3f588d6aff12c1ceb11
Show changes to git-request-pull.sh +3 −3
diff --git a/git-request-pull.sh b/git-request-pull.sh
index ae6cd27..e199a91 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -6,9 +6,9 @@
 
 usage()
 {
-	echo "$0 <commit> <url> [ <head> ]"
-	echo "  Summarizes the changes since <commit> to the standard output,"
-	echo "  and includes <url> in the message generated."
+	echo >&2 "usage: $0 <commit> <url> [<head>]"
+	echo >&2 '  Summarizes the changes since <commit> to the standard output,'
+	echo >&2 '  and includes <url> in the message generated.'
 	exit 1
 }
 
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 20/25] git-reset: Use $0 instead of program name in usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-reset.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
33cc93a9e686c0daa64e430bf44b441809fd1025
Show changes to git-reset.sh +1 −1
diff --git a/git-reset.sh b/git-reset.sh
index 72ef303..58600fc 100755
--- a/git-reset.sh
+++ b/git-reset.sh
@@ -2,7 +2,7 @@
 . git-sh-setup
 
 usage () {
-	die 'Usage: git reset [--mixed | --soft | --hard]  [<commit-ish>]'
+	die 'usage: $0 [--mixed | --soft | --hard]  [<commit-ish>]'
 }
 
 tmp=/var/tmp/reset.$$
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 17/25] git-relink: Print usage message to stderr.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-relink.perl |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
c8f3a2016fcd16470507af70bf4de17de3881f6f
Show changes to git-relink.perl +5 −5
diff --git a/git-relink.perl b/git-relink.perl
index f6b4f6a..816e238 100755
--- a/git-relink.perl
+++ b/git-relink.perl
@@ -163,11 +163,11 @@ sub link_two_files($$) {
 
 
 sub usage() {
-	print("Usage: $0 [--safe] <dir> [<dir> ...] <master_dir> \n");
-	print("All directories should contain a .git/objects/ subdirectory.\n");
-	print("Options\n");
-	print("\t--safe\t" .
+	print STDERR "usage: $0 [--safe] <dir> [<dir>...] <master_dir>\n";
+	print STDERR "All directories should contain a .git/objects/ subdirectory.\n";
+	print STDERR "Options\n";
+	print STDERR "\t--safe\t" .
 		"Stops if two objects with the same hash exist but " .
-		"have different sizes.  Default is to warn and continue.\n");
+		"have different sizes.  Default is to warn and continue.\n";
 	exit(1);
 }
-- 
0.99.9.GIT
Junio C Hamano· Dec 11, 2005, 04:26 UTC · re: freku045@student.liu.se · lore

Re: [PATCH 17/25] git-relink: Print usage message to stderr.

freku045@student.liu.se writes:
Show 7 quoted lines
> +	print STDERR "usage: $0 [--safe] <dir> [<dir>...] <master_dir>\n";
> +	print STDERR "All directories should contain a .git/objects/ subdirectory.\n";
> +	print STDERR "Options\n";
> +	print STDERR "\t--safe\t" .
>  		"Stops if two objects with the same hash exist but " .
> -		"have different sizes.  Default is to warn and continue.\n");
> +		"have different sizes.  Default is to warn and continue.\n";
Might be cleaner to use <<HERE document here.
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 18/25] git-repack: Print usage message on unrecognized option.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-repack.sh |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
3616296531a068dcbe5a39f8864ddde3b3067969
Show changes to git-repack.sh +6 −1
diff --git a/git-repack.sh b/git-repack.sh
index 430ddc5..9752032 100755
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -4,7 +4,11 @@
 #
 
 . git-sh-setup
-	
+
+usage () {
+	die "usage: $0 [-a] [-d] [-l] [-n]"
+}
+
 no_update_info= all_into_one= remove_redundant= local=
 while case "$#" in 0) break ;; esac
 do
@@ -13,6 +17,7 @@ do
 	-a)	all_into_one=t ;;
 	-d)	remove_redundant=t ;;
 	-l)	local=t ;;
+	-*)	usage ;;
 	*)	break ;;
 	esac
 	shift
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 21/25] git-send-email: Usage message clean-up.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-send-email.perl |   62 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 34 insertions(+), 28 deletions(-)
38fde073a59d00a19111a30e8f804c4e784835e7
Show changes to git-send-email.perl +34 −28
diff --git a/git-send-email.perl b/git-send-email.perl
index ec1428d..5f6b729 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -27,6 +27,38 @@ use Email::Valid;
 sub unique_email_list(@);
 sub cleanup_compose_files();
 
+sub usage {
+	print <<EOT;
+$0 [options] <file | directory> [... file | directory ]
+Options:
+   --from         Specify the "From:" line of the email to be sent.
+
+   --to           Specify the primary "To:" line of the email.
+
+   --compose      Use \$EDITOR to edit an introductory message for the
+                  patch series.
+
+   --subject      Specify the initial "Subject:" line.
+                  Only necessary if --compose is also set.  If --compose
+		  is not set, this will be prompted for.
+
+   --in-reply-to  Specify the first "In-Reply-To:" header line.
+                  Only used if --compose is also set.  If --compose is not
+		  set, this will be prompted for.
+
+   --chain-reply-to If set, the replies will all be to the previous
+                  email sent, rather than to the first email sent.
+                  Defaults to on.
+
+   --smtp-server  If set, specifies the outgoing SMTP server to use.
+                  Defaults to localhost.
+EOT
+
+	print $_[0], "\n" if defined $_[0];
+
+	exit(1);
+}
+
 # Constants (essentially)
 my $compose_filename = ".msg.$$";
 
@@ -51,6 +83,7 @@ my $rc = GetOptions("from=s" => \$from,
 		    "chain-reply-to!" => \$chain_reply_to,
 		    "smtp-server=s" => \$smtp_server,
 		    "compose" => \$compose,
+		    "help|h" => sub { usage; },
 	 );
 
 # Now, let's fill any that aren't set in with defaults:
@@ -187,34 +220,7 @@ for my $f (@ARGV) {
 if (@files) {
 	print $_,"\n" for @files;
 } else {
-	print <<EOT;
-git-send-email [options] <file | directory> [... file | directory ]
-Options:
-   --from         Specify the "From:" line of the email to be sent.
-
-   --to           Specify the primary "To:" line of the email.
-
-   --compose      Use \$EDITOR to edit an introductory message for the
-                  patch series.
-
-   --subject      Specify the initial "Subject:" line.
-                  Only necessary if --compose is also set.  If --compose
-		  is not set, this will be prompted for.
-
-   --in-reply-to  Specify the first "In-Reply-To:" header line.
-                  Only used if --compose is also set.  If --compose is not
-		  set, this will be prompted for.
-
-   --chain-reply-to If set, the replies will all be to the previous
-                  email sent, rather than to the first email sent.
-                  Defaults to on.
-
-   --smtp-server  If set, specifies the outgoing SMTP server to use.
-                  Defaults to localhost.
-
-Error: Please specify a file or a directory on the command line.
-EOT
-	exit(1);
+	usage "Error: Please specify a file or a directory on the command line.";
 }
 
 # Variables we set as part of the loop over files
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 23/25] git-tag: Clean-up usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-tag.sh |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
3a3150d9fbd640ffb269fc49a322c04466e700f5
Show changes to git-tag.sh +2 −8
diff --git a/git-tag.sh b/git-tag.sh
index 2435a75..f4a0150 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -1,16 +1,10 @@
 #!/bin/sh
 # Copyright (c) 2005 Linus Torvalds
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
+. git-sh-setup
 
 usage () {
-    echo >&2 "Usage: git-tag [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]"
-    exit 1
-}
-
-die () {
-    echo >&2 "$*"
-    exit 1
+    die "usage: $0 [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]"
 }
 
 annotate=
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:37 UTC · re: freku045@student.liu.se · lore

[PATCH 22/25] git-status: Print usage message on incorrect invocation.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-status.sh |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
5bce9bb1977eea80398f894880340f10bdc9a2eb
Show changes to git-status.sh +11 −1
diff --git a/git-status.sh b/git-status.sh
index 2dda0c5..4ba6cc2 100755
--- a/git-status.sh
+++ b/git-status.sh
@@ -2,7 +2,17 @@
 #
 # Copyright (c) 2005 Linus Torvalds
 #
-GIT_DIR=$(git-rev-parse --git-dir) || exit
+
+. git-sh-setup
+
+usage () {
+	die "usage: $0"
+}
+
+if [ "$#" != "0" ]
+then
+    usage
+fi
 
 report () {
   header="#
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:38 UTC · re: freku045@student.liu.se · lore

[PATCH 25/25] git-mv: Clean-up usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-mv.perl |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
a213190dc8f25c133046a35593e027cb748f662b
Show changes to git-mv.perl +9 −1
diff --git a/git-mv.perl b/git-mv.perl
index 83dc7e4..db6699d 100755
--- a/git-mv.perl
+++ b/git-mv.perl
@@ -12,13 +12,21 @@ use strict;
 use Getopt::Std;
 
 sub usage() {
-	print <<EOT;
+	print STDERR <<EOT;
 $0 [-f] [-n] <source> <destination>
 $0 [-f] [-n] [-k] <source> ... <destination directory>
 EOT
 	exit(1);
 }
 
+sub HELP_MESSAGE() {
+	usage;
+}
+
+sub VERSION_MESSAGE() {
+	usage;
+}
+
 my $GIT_DIR = `git rev-parse --git-dir`;
 exit 1 if $?; # rev-parse would have given "not a git dir" message.
 chomp($GIT_DIR);
-- 
0.99.9.GIT
freku045@student.liu.se· Dec 10, 2005, 19:38 UTC · re: freku045@student.liu.se · lore

[PATCH 24/25] git-verify-tag: Clean-up usage message.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
---
 git-verify-tag.sh |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
54db71ed3add0583463d77645e840ef61c8c6d9c
Show changes to git-verify-tag.sh +5 −5
diff --git a/git-verify-tag.sh b/git-verify-tag.sh
index 1f44da5..aff7c68 100755
--- a/git-verify-tag.sh
+++ b/git-verify-tag.sh
@@ -1,14 +1,14 @@
 #!/bin/sh
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
+. git-sh-setup
 
-die () {
-    echo >&2 "$*"
-    exit 1
+usage () {
+    echo >&2 "usage: $0 [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]"
+    die "$@"
 }
 
 type="$(git-cat-file -t "$1" 2>/dev/null)" ||
-	die "$1: no such object."
+	usage "$1: no such object."
 
 test "$type" = tag ||
 	die "$1: cannot verify a non-tag object of type $type."
-- 
0.99.9.GIT
A Large Angry SCM· Dec 10, 2005, 22:13 UTC · re: freku045@student.liu.se · lore

Re: [PATCH 0/25] Usage message clean-up

freku045@student.liu.se wrote: ...

> I have tried to follow the following rules:
> 
> * Any unrecognised options should make the script die with the usage
>   message.
Good.
> * -h and --help makes the script die with the usage message.
This should not be an error. The user was asking for the usage message.
> * The message is printed to stderr.

Good unless the message was printed due to -h or --help, then it should go to stdout.

Show 7 quoted lines
> * The message is of the form "usage: $0 options"
> 
> I am not convinced that the last bullet point is the best way to do
> things. Using "$0" is probably best for Git developers but using "git
> program-name" is probably least confusing for users, especially if we
> are going to move the git-* binaries away from /usr/bin. Another
> option is "basename $0". What do you think?

Not using $0 can make it _extremely_ annoying to determine exactly which program printed the usage message. It may look prettier without the path but if I have more that one $(basename $0) it may not be trivial to determine the one that issued the message. Also keep in mind that is it possible to have spaces in names of executables. So, "foo-bar" and "foo bar" may be two different executables.

Johannes Schindelin· Dec 10, 2005, 22:50 UTC · re: freku045@student.liu.se · lore

Re: [PATCH 0/25] Usage message clean-up

Hi,
On Sat, 10 Dec 2005, freku045@student.liu.se wrote:
> * Any unrecognised options should make the script die with the usage
>   message.
Good.
> * -h and --help makes the script die with the usage message.
Good.
> * The message is printed to stderr.
Arguable.
> * The message is of the form "usage: $0 options"
Not good. We are in a transition to "git whatever" from "git-whatever".

Besides, I have to admit that I am a bit annoyed by 25 mini mails for the same purpose.

Hth, Dscho

Junio C Hamano· Dec 11, 2005, 02:58 UTC · re: Johannes Schindelin · lore

Re: [PATCH 0/25] Usage message clean-up

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>> * -h and --help makes the script die with the usage message.
>
> Good.

Supporting -h and --help are good, but we probably do not want to exit with non-zero status in such a case. Not a big deal, though.

>> * The message is printed to stderr.
>
> Arguable.

One thing I really hate is a program that does more than one pageful of help message to stderr which forces me to do "blah

>&2 --help | less", but our help messages are short and sweet,
so I feel stderr is OK.
>> * The message is of the form "usage: $0 options"
>
> Not good. We are in a transition to "git whatever" from "git-whatever".

But when the user wishes to look at the manual page, he needs to say "man git-whatever", so either way you cannot win. I'm neutral either way, as long as we are consistent.

> Besides, I have to admit that I am a bit annoyed by 25 mini mails for the 
> same purpose.

I'd appreciate the flexibility of reviewing them indivudually, especially when some of them seem to change the structure of the argument parsing loop.

Nikolai Weibull· Dec 11, 2005, 11:16 UTC · re: freku045@student.liu.se · lore

Re: [PATCH 0/25] Usage message clean-up

freku045@student.liu.se wrote:
> * The message is of the form "usage: $0 options"

I don’t really care, but most GNU utils seem to use a large 'U' in "Usage". Is there a particular reason that git doesn't? (Other than git not being GNU software?)

        nikolai
-- 
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

← back to recent threads