Skip to contentSkip to conversation

Make cg more robust and user friendly

PATCH New Jonas Fonseca 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make cg more robust and user friendly

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.

---
commit 5e15803563ef00720541e89ae16a633ac8dfb7d7
tree 90374bdbc77b04bc5bfa4365e291e3603b0a7099
parent 20282cdd610ecef03c8c97853bc0749ef3ab32b3
author Jonas Fonseca <[email protected]> Thu, 29 Sep 2005 15:12:02 +0200 committer Jonas Fonseca <[email protected]> Thu, 29 Sep 2005 15:12:02 +0200

 cg |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
cg +12 -5
@@ -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
Signature · 1 line
Jonas Fonseca