Skip to content

Commit 4253eb2

Browse files
Fixed(scripts/termux-call-log): Exit with error for invalid -l and -o options
Co-authored-by: @EmilyGraceSeville7cf <[email protected]> Co-authored-by: @agnostic-apollo <[email protected]>
1 parent e62bdad commit 4253eb2

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

scripts/termux-call-log.in

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
11
#!@TERMUX_PREFIX@/bin/bash
22
set -u
33

4-
PARAM_LIMIT=10
5-
PARAM_OFFSET=0
4+
PARAM_LIMIT_DEFAULT=10
5+
PARAM_LIMIT="$PARAM_LIMIT_DEFAULT"
6+
7+
PARAM_OFFSET_DEFAULT=0
8+
PARAM_OFFSET="$PARAM_OFFSET_DEFAULT"
9+
610
PARAMS=""
711

812
SCRIPTNAME=termux-call-log
913

14+
validate_is_postive_number() {
15+
if [[ ! "${2:-}" =~ ^[0-9]+$ ]]; then
16+
echo "ERROR: The -$1 value '${2:-}' is not a positive number." 1>&2
17+
show_usage || return $?
18+
exit 1
19+
fi
20+
}
21+
1022
show_usage () {
11-
echo "Usage: $SCRIPTNAME [-l limit] [-o offset]"
23+
echo "Usage: $SCRIPTNAME [-l <limit>] [-o <offset>]"
1224
echo "List call log history"
13-
echo " -l limit offset in call log list (default: $PARAM_LIMIT)"
14-
echo " -o offset offset in call log list (default: $PARAM_OFFSET)"
15-
exit 0
25+
echo " -l <limit> limit in call log list (default: $PARAM_LIMIT_DEFAULT)"
26+
echo " -o <offset> offset in call log list (default: $PARAM_OFFSET_DEFAULT)"
1627
}
1728

1829
while getopts :hl:o: option
1930
do
2031
case "$option" in
21-
h) show_usage;;
22-
l) PARAM_LIMIT=$OPTARG;;
23-
o) PARAM_OFFSET=$OPTARG;;
32+
h) show_usage; exit 0;;
33+
l) PARAM_LIMIT="$OPTARG";;
34+
o) PARAM_OFFSET="$OPTARG";;
2435
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
2536
esac
2637
done
2738
shift $((OPTIND-1))
2839

40+
validate_is_postive_number l "$PARAM_LIMIT"
41+
validate_is_postive_number o "$PARAM_OFFSET"
42+
2943
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
3044

3145
PARAMS="$PARAMS --ei offset $PARAM_OFFSET --ei limit $PARAM_LIMIT"

0 commit comments

Comments
 (0)