summaryrefslogtreecommitdiff
path: root/init
blob: 2ba23ec6c49bf60633d4209d4c02c18e8fa60b66 (plain)
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
#!/usr/bin/env sh

usage="usage: init <directory> <language>"
puzzle=${1?$usage}
lang=${2?$usage}

# get directory of this script
script=$(readlink -f "$0")
script_path=$(dirname "$script")

puzzle_path="$script_path"/"$puzzle"

mkdir --parents "$puzzle_path"
touch "$puzzle_path"/puzzle.txt

# data directory
if [ ! -d "$puzzle_path"/data ]; then
	mkdir "$puzzle_path"/data

	touch "$puzzle_path"/data/test.txt
	touch "$puzzle_path"/data/test.ans
fi

case $lang in
python)
	cp "$script_path"/template/python.py "$puzzle_path"
	;;
rust)
	cargo new --vcs none --name puzzle "$puzzle_path"/rust
	cp "$script_path"/template/main.rs "$puzzle_path"/rust/src/main.rs
	;;
*)
	echo unknown lang: "$lang"
	exit 1
	;;
esac