summaryrefslogtreecommitdiff
path: root/pbs-help
blob: 35157b8b6874ecafc6d83766afe9974cd250ab63 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash -euE

. libremessages

stem=pbs

presort() {
	local r
	while read -r cmd; do
		r=6
		case "$cmd" in
			help) r=0;;
			init) r=1;;

			download|upload) r=2;;

			package-fork|package-new) r=3;;
			package-*commit) r=5;;
			package-*) r=4;;

			convert-*) r=8;;
			plumb-*) r=9;;
		esac
		printf '%d;%s\n' "$r" "$cmd"
	done
}

postsort() {
	cut -d';' -f2
}

list_commands() {
	find ${PATH//:/ } -type f -executable -name "$stem-*" \
		-printf '%f\n' 2>/dev/null | sed "s/^${stem}-//;/--/d" |
	presort | sort | postsort
}

master_usage() {
	echo "Usage: ${stem} COMMAND [OPTIONS]"
	echo "Parabola Build System"
	echo
	echo "plumb-* commands are for internal use."
	echo
	echo "Commands:"
	list_commands | while read -r cmd; do
		help="$("$stem-$cmd" -h|sed -n 2p)"
		printf '  %-20s  %s\n' "$cmd" "$help"
	done
}

help_usage() {
	echo "Usage: ${stem} help [OPTIONS] COMMAND"
	echo "Shows the manual page for a command."
	echo ''
	echo 'Options:'
	echo '  -h            Show this message'
}

main() {
	if [[ $# < 1 ]]; then
		master_usage
	else
		if in_array '-h' "$@"; then
			help_usage
		else
			man "$stem-$1"
		fi
	fi
}

main "$@"