From 5edc00087343c9f1af7f345b86914c1f0fa94bfd Mon Sep 17 00:00:00 2001 From: merakor Date: Sat, 7 Aug 2021 21:00:10 +0000 Subject: global_options: add argument to call silent FossilOrigin-Name: cab50844d5456d5bb7c10625e3f34038146b84780b93f3abed107c74378cc41f --- src/cpt-lib.in | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/cpt-lib.in') diff --git a/src/cpt-lib.in b/src/cpt-lib.in index c055331..0017fba 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -415,14 +415,29 @@ getoptions_help() { echo "}" } +# 2086: +# The lack of quotes are intentional. We do this so `getoptions()` do not try +# to parse the empty string. +# 2120: +# The library does not call this function with any positional arguments, but +# that does not mean that other programs will not do it, so this can also be +# safely ignored. +# shellcheck disable=2086,2120 global_options() { - msg -- '' 'Global Options:' - flag CPT_FORCE -f --force init:@export -- "Force operation" - flag CPT_PROMPT -y --no-prompt on:0 off:0 init:@export -- "Do not prompt for confirmation" - param CPT_ROOT --root init:@export -- "Use an alternate root directory" - disp :usage -h --help -- "Show this help message" - disp :version -v --version -- "Print version information" - flag CPT_VERBOSE --verbose init:@export -- "Be more verbose" + # These are options that are supported by most utilities. If the optional + # argument 'silent' is given, the usage will not print these options, but + # the arguments will still be accepted. Sometimes it doesn't make sense to + # pollute the screen with options that will be rarely ever used. + case $1 in + silent) h=hidden:1 ;; + *) msg -- '' 'Global Options:'; h='' + esac + flag CPT_FORCE -f --force $h init:@export -- "Force operation" + flag CPT_PROMPT -y --no-prompt on:0 off:0 $h init:@export -- "Do not prompt for confirmation" + param CPT_ROOT --root $h init:@export -- "Use an alternate root directory" + disp :usage -h --help $h -- "Show this help message" + disp :version -v --version $h -- "Print version information" + flag CPT_VERBOSE --verbose $h init:@export -- "Be more verbose" } contains() { -- cgit v1.2.3