threads / patch / 1995

patchMake cg more robust and user friendly

Subject: [PATCH Cogito] Make cg more robust and user friendly

## tl;dr

One message between Oct 2, 2005 and Oct 2, 2005. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Jonas Fonseca· Oct 2, 2005, 10:13 UTC · lore

Accept -h in addition to --help. Error out on unknown options. Convert to be a real bash script and slightly simplify the control flow, so we can use the 'type' builtin command for checking if the requested Cogito command exists in the PATH.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

--- commit 5e15803563ef00720541e89ae16a633ac8dfb7d7 tree 90374bdbc77b04bc5bfa4365e291e3603b0a7099 parent 20282cdd610ecef03c8c97853bc0749ef3ab32b3 author Jonas Fonseca <fonseca@diku.dk> Thu, 29 Sep 2005 15:12:02 +0200 committer Jonas Fonseca <fonseca@stud1-9.itu.dk> Thu, 29 Sep 2005 15:12:02 +0200

 cg |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
Show changes to cg +12 −5
diff --git a/cg b/cg
--- a/cg
+++ b/cg
@@ -1,9 +1,16 @@
-#!/bin/sh
+#!/usr/bin/env bash
 
-[ x"$1" = "x" ] && exec cg-help
 cmd="$1"; shift
-( [ x"$cmd" = x"--help" ] ) && exec cg-help
-( [ x"$cmd" = x"--version" ] ) && exec cg-version
+case "$cmd" in
+-h|--help|"") cmd="help" ;;
+--version) cmd="version" ;;
+-*)
+	echo "cg: unknown option '$cmd' (try 'cg --help' or 'cg --version')" >&2
+	exit 1
+esac
 
 exe="cg-$cmd"
-exec $exe "$@"
+type -P "$exe" >/dev/null && exec "$exe" "$@"
+
+echo "cg: unknown command '$cmd' (try 'cg help')" >&2
+exit 1
-- 
Jonas Fonseca

← back to recent threads