Files
mpbb/mpbb-help
Lawrence Velázquez d39d16cc99 mpbb: Implement new help system
The `--help` option has been replaced by a new `help` subcommand.
Invoking `mpbb help` displays global usage and available subcommands,
while `mpbb help <subcommand>` displays subcommand-specific usage.

Each subcommand script `mpbb-FOO` must now define a function `FOO-usage`
that prints its specific help to standard out.

git-svn-id: https://svn.macports.org/repository/macports/contrib/mp-buildbot@152528 d073be05-634f-4543-b044-5fe20cf6d1d6
2016-09-12 01:59:04 +00:00

38 lines
1.0 KiB
Bash

#!/bin/bash
# -*- coding: utf-8; mode: sh; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=sh:et:sw=4:ts=4:sts=4
# Note:
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
help-usage() {
cat <<EOF
usage: $prog help [<command>]
Show usage information for \`$prog' or a specific \`$prog' subcommand.
Run \`$prog help' for global options and a list of other subcommands.
EOF
}
help() {
local cols helpfunc prog
cols=$(tput cols) || cols=80
# The main program should define "mpbb-usage", which is called if
# "mpbb help" is invoked without any arguments.
helpfunc=${1-mpbb}-usage
prog=$(basename "$0")
readonly cols helpfunc prog
# This loop exits with 0 if usages contains helpfunc or is empty.
for usage in "${usages[@]}"; do
[[ $usage == "$helpfunc" ]] && break
done
if (( $? != 0 || ${#usages[@]} == 0 )); then
err "No help available for subcommand \`${helpfunc%-usage}'"
return 2
fi
"$helpfunc" | fmt -w $((cols - 8)) >&2
}