Skip to content

Commit

Permalink
feat: ✨ add -i flag to initialize the project directory with the defa…
Browse files Browse the repository at this point in the history
…ult directory structure

Signed-off-by: Eric Villard <[email protected]>
  • Loading branch information
eviweb committed Sep 16, 2022
1 parent f7d741a commit 1652dde
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 9 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ usage()
Options:
-f force overwriting files
-h display this help message
-i initialize the current project directory
-V display the version number
-v set verbosity level, can be used multiple times
USAGE
Expand Down Expand Up @@ -193,16 +194,23 @@ run_scripts()
done
}

initialize()
{
mkdir -p "$(main_dir)"/config/{copy,link,run}
}

if ! is_sourced; then
VERBOSITY=0
OVERWRITING="-i"

while getopts "fhVv" option; do
while getopts "fhiVv" option; do
case "${option}" in
f) OVERWRITING="-f"
;;
h) usage && exit 0
;;
i) initialize && exit $?
;;
V) version && exit 0
;;
v) ((VERBOSITY=VERBOSITY+1))
Expand Down
21 changes: 21 additions & 0 deletions tests/init-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
tempdir="$(mktemp -d)"

[ -d "${tempdir}" ] || {
echo -e "Failed to create ${tempdir}"
exit 1
}

dirs=(
"${tempdir}/config/copy"
"${tempdir}/config/link"
"${tempdir}/config/run"
)

cp "$(main_dir)"/install.sh "${tempdir}"
"${tempdir}"/install.sh -i

for dir in "${dirs[@]}"; do
assert_dir_exists "${dir}"
done

rm -rf "${tempdir}"

0 comments on commit 1652dde

Please sign in to comment.