2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 function cli_help_requested
() {
25 if [ -n "${argument}" ]; then
26 if listmatch
${argument} help -h --help; then
34 function cli_zone_headline
() {
37 cli_status_headline
${zone}
40 function cli_status_headline
() {
43 local state
="${COLOUR_DOWN}DOWN${COLOUR_NORMAL}"
44 zone_is_up
${zone} && state="${COLOUR_UP}UP${COLOUR_NORMAL}"
46 echo -e "${zone} - ${state} - $(zone_get_hook ${zone})"
49 function cli_headline() {
54 local ident=$(cli_ident ${level})
56 printf "${ident}${COLOUR_BOLD}$@${COLOUR_NORMAL}\n"
59 function cli_print() {
64 local ident=$(cli_ident $(( ${level} + 1 )))
67 printf -v out "${ident}${format}\n" "$@
"
71 function cli_print_fmt1() {
75 local space=$(( 30 - (${level} * 4) ))
76 local format="%-${space}s
%s
"
78 cli_print ${level} "${format}" "$@
"
81 function cli_print_bool() {
82 if [ "${1}" = "${EXIT_TRUE}" ]; then
89 function cli_print_yesno() {
90 if [ "${1}" = "${EXIT_TRUE}" ]; then
97 function cli_space() {
101 function cli_ident() {
106 while [ ${level} -gt 1 ]; do
108 level=$(( ${level} - 1 ))
114 function cli_yesno() {
115 local message="$@
[y
/n
] "
119 printf "\n${message}"
123 if listmatch ${yesno} y Y yes YES Yes; then
127 elif listmatch ${yesno} n N no NO No; then
133 function cli_get_key() {
138 function cli_get_val() {
142 function cli_usage() {
144 local basename="$
(basename ${0})"
146 if ! isset command; then
147 command="${basename} help"
150 echo "The given
command was not understood by
${basename}.
" >&2
151 echo "Please run
'${command}' for detailed
help.
" >&2
154 function cli_show_man() {
158 if ! binary_exists man; then
159 error "The man package is not installed on this system.
"
160 error "Please
install 'man' in order to view the
help.
"