aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin/coll2path
blob: 79b2f53ea690f0a5015d6ec38a12dfddef77aa98 (about) (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
set -eu

usage() {
	cat <<-'EOF'
		Usage:
		  coll2path LANGUAGE COLLECTION
		  coll2path -h
	EOF
}

help() {
	cat <<-'EOF'


		Options:
		  -h, --help    show this message

		  LANGUAGE      in which language to list the collections
		                 names for
		  COLLECTION    what collection to get the path for


		Get the path for the COLLECTION, doing the proper translation
		on the way, and checking if is "article".


		Examples:

		  Get the path for "TIL" in portuguese:

		    $ coll2path pt til
		    hea/


		  Get the path for "articles" in english

		    $ collections en articles

	EOF
}


for flag in "$@"; do
	case "$flag" in
		--)
			break
			;;
		--help)
			usage
			help
			exit
			;;
		*)
			;;
	esac
done

while getopts 'h' flag; do
	case "$flag" in
		h)
			usage
			help
			exit
			;;
		*)
			usage >&2
			exit 2
	esac
done
shift $((OPTIND - 1))

. src/lib.sh


LANGUAGE="${1:-}"
COLLECTION="${2:-}"
eval "$(assert_arg "$LANGUAGE"   'LANGUAGE')"

# shellcheck source=/dev/null
. src/lib/commencement."$LANGUAGE".conf

if [ -z "$COLLECTION" ]; then
	echo "${article_collection_name:-}"
else
	NAME="$(eval "echo \"\$${COLLECTION}_collection_name\"")"
	echo "$NAME${NAME:+/}"
fi