#!/usr/pkg/bin/bash
#
# Wrapper for running Cogito commands.
# Copyright (c) Petr Baudis, 2005
#
# Takes a variable number of arguments where the first argument should
# either be a Cogito command or one of the supported options. If no
# arguments are specified an overview of all the Cogito commands will be
# shown.
#
# Enables all Cogito commands to be accessed as subcommands, for example
# is:
#
#	cg help
#	cg-help
#
# equivalent.
#
# OPTIONS
# -------
# --version:: Show the Cogito toolkit version
#	Show the version of the Cogito toolkit. Equivalent to the output
#	of `cg-version`.

USAGE="cg [--version | COMMAND [ARGS]...]"

cmd="$1"; shift
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"

# Cut'n'pasted from cg-Xlib
save_IFS="$IFS"; IFS=:
for dir in $PATH; do
	IFS="$save_IFS"
	exefile="$dir/$exe"
	[ -x "$exefile" ] && exec "$exefile" "$@"
done
IFS="$save_IFS"

echo "cg: unknown command '$cmd' (try 'cg help')" >&2
exit 1
