summaryrefslogtreecommitdiff
path: root/src/assert-arg
blob: 8eaaea803d6c474c78ce145165f6088c2e7083e6 (plain) (blame)
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
#!/bin/sh
set -eu

usage() {
	cat <<-'EOF'
		Usage:
		  assert-arg [--] STRING MESSAGE
	EOF
}


if [ "${1:-}" = '--' ]; then
	shift
fi

if [ $# -ne 2 ]; then
	usage >&2
	exit 2
fi

STRING="$1"
MESSAGE="$2"

if [ -z "$STRING" ]; then
	printf 'Missing %s.\n\n' "$MESSAGE" >&2
	cat <<-'EOF'
		usage >&2
		exit 2
	EOF
fi