git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH Cogito] Make cg more robust and user friendly

From
Jonas Fonseca <fonseca@diku.dk>
Date
Oct 2, 2005, 10:13 UTC
Message-ID
<20051002101306.GB9219@diku.dk>

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(-)
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
Message 1 of 1 in “Make cg more robust and user friendly”
  1. Make cg more robust and user friendlyJonas Fonseca, Oct 2, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.