-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargs.bash
More file actions
30 lines (29 loc) · 809 Bytes
/
args.bash
File metadata and controls
30 lines (29 loc) · 809 Bytes
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
# Tools for argument parsing
# ## _args_input_files_or_stdin
#
# * Parses the passed arguments as filenames or '-'
# * if args is a single dash `-` => `(/dev/stdin)`
# * Makes sure they exist
# * Puts them in array '_ARGS_INPUT_FILES'
#
export _ARGS_INPUT_FILES
declare -a _ARGS_INPUT_FILES
_args_input_files_or_stdin() {
##
## * `<source-files>` - 1..n filenames. Pass a single `-` to read from `STDIN`
##
if [[ "$1" == "-" ]];then
_ARGS_INPUT_FILES+=(/dev/stdin)
shift
if [[ ! -z "$1" ]];then
shlog -l error -x 10 "Don't mix input files and STDIN."
fi
fi
while [[ ! -z "$1" ]];do
if [[ ! -e "$1" ]];then
shlog -l error -x 10 "No such file: '$1'"
fi
_ARGS_INPUT_FILES+=("$1")
shift
done
}