Skip to content

Commit

Permalink
Add argument count checks
Browse files Browse the repository at this point in the history
  • Loading branch information
urbanware-org committed Apr 4, 2020
1 parent 3b7da03 commit 74a707c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions salomon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ else
case "$arg" in
# Required arguments
-a|--action)
if [ ! -z "$action" ]; then
usage "The action argument can only be given once"
fi
shift
action="$1"
shift
Expand All @@ -63,6 +66,9 @@ else

# Optional arguments
-c|--color-file)
if [ ! -z "$color_file" ]; then
usage "The color file argument can only be given once"
fi
shift
color_file="$1"
check_argument "-c/--color-file" "$color_file" "file"
Expand All @@ -82,26 +88,43 @@ else
shift
;;
-e|--exclude)
if [ ! -z "$exclude_pattern" ]; then
usage "The exclude argument can only be given once" \
"Use use a pattern instead"
fi
shift
exclude_pattern="$1"
shift
;;
--export-file)
if [ ! -z "$export_file" ]; then
usage "The export argument can only be given once"
fi
shift
export_file="$1"
export_log=1
shift
;;
-f|--filter)
if [ ! -z "$filter_pattern" ]; then
usage "The filter argument can only be given once" \
"Use use a pattern instead"
fi
shift
filter_pattern="$1"
shift
;;
--force-dark)
if [ ! -z "$color_force" ]; then
usage "The force dark argument can only be given once"
fi
color_force="dark"
shift
;;
--force-light)
if [ ! -z "$color_force" ]; then
usage "The force light argument can only be given once"
fi
color_force="light"
shift
;;
Expand Down Expand Up @@ -149,6 +172,10 @@ else
shift
;;
-r|--remove)
if [ ! -z "$remove_pattern" ]; then
usage "The remove argument can only be given once" \
"Use use a pattern instead"
fi
shift
remove_pattern="$1"
shift
Expand Down Expand Up @@ -186,17 +213,26 @@ else

# Alternatives to the required arguments
--analyze)
if [ ! -z "$action" ]; then
usage "An action argument can only be given once"
fi
action="analyze"
shift
;;
--monitor)
if [ ! -z "$action" ]; then
usage "An action argument can only be given once"
fi
action="monitor"
shift
;;

# Backwards compatibility arguments (still existing, but no longer
# listed inside the usage information)
--config-file)
if [ ! -z "$color_file" ]; then
usage "The color file argument can only be given once"
fi
shift
color_file="$1"
check_argument "--config-file" "$color_file" "file"
Expand Down

0 comments on commit 74a707c

Please sign in to comment.