aboutsummaryrefslogtreecommitdiff
blob: a65cf36f1da3fe43442eee2054218cb74ae65c5d (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*-eselect-*-  vim: ft=eselect
# Copyright (c) 2005-2012 Gentoo Foundation
# $Id$
# This file is part of the 'eselect' tools framework.
#
# eselect is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 2 of the License, or (at your option) any later
# version.
#
# eselect is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# eselect.  If not, see <http://www.gnu.org/licenses/>.

DESCRIPTION="No description available"
VERSION="No version available"
DEFAULT_ACTION="usage"

describe_usage() {
	echo "Display usage information"
}

do_usage() {
	show_usage_message
}

show_usage_message() {
	local action

	echo "Usage: ${ESELECT_COMMAND} <action> <options>"
	echo

	write_list_start "Standard actions:"
	for action in help usage version; do
		local desc=""
		is_function "describe_${action}" && desc=$(describe_${action})
		write_kv_list_entry "${action}" "${desc:-(no description)}"
	done

	echo
	write_list_start "Extra actions:"

	# FIXME: can we do this using expansion somehow?
	for action in $(set | \
			sed -n -e '/^do_\S\+ ()\s*$/s/^do_\(\S\+\).*/\1/p' | \
			grep -v 'action' | \
			sort); do
		case "${action}" in
			help|usage|version)
				continue
				;;
			?*)
				local desc="" ifs_save="${IFS}" action_text line options
				is_function "describe_${action}" && desc=$(describe_${action})

				if is_function "describe_${action}_parameters"; then
					action_text="${action} $(describe_${action}_parameters)"
				else
					action_text="${action}"
				fi

				write_kv_list_entry "${action_text}" "${desc:-(no description)}"

				if is_function "describe_${action}_options"; then
					options=$(describe_${action}_options)
					IFS=$'\n'
					for line in ${options}; do
						write_kv_list_entry -p \
							"  ${line%%*( ):*}" \
							"  ${line##+([^:]):*( )}"
					done
					IFS="${ifs_save}"
				fi
				;;
		esac
	done
	true
}

describe_version() {
	echo "Display version information"
}

do_version() {
	echo "Version ${VERSION}"
}

describe_help() {
	echo "Display help text"
}

do_help() {
	set_output_mode default
	echo "${DESCRIPTION}"
	show_usage_message
	if is_function show_extra_help_text; then
		echo
		show_extra_help_text
	fi
	true
}