-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
mpbb-help
37 lines (30 loc) · 1.05 KB
/
mpbb-help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/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
}