All ProjectsHome
csb
csb/src/libexec/csb-help
csb-help Raw
#!/bin/bash
set -eo pipefail

command_path() {
    command -v "csb-$1" || true
}

print_help() {
    local file="$1"

    local help="$($file -h 2>/dev/null)" && echo "$help" \
        || echo "Sorry, this command isn't documented yet"
}

commands() {
    #This goes through the entire $PATH to reflect how
    # the `csb` command actually works
    (
    shopt -s nullglob
    for path in ${PATH//:/$'\n'}; do
        for command in "${path}/csb-"*; do
            echo "${command##*csb-}"
        done
    done
    ) | sort | uniq
}

HELP="Usage: csb <command> [<args>]

Some useful commands:
  csb init        Initialize a new csb site
  csb addrepo     Add a repository to a csb site
  csb build       Build a csb site

All commands:
$(commands)

See 'csb help <command>' for information on a specific command."

command="$1"
case "$command" in
    "") echo "$HELP"
        ;;
    "commands")
        commands
        ;;
    *)
        file="$(command_path "$command")"

        if [ -n "$file" ]; then
            print_help "$file"
        else
            echo "csb: no such command \`$command\`" >&2
            exit 1
        fi
esac