cleanup file tree function
This commit is contained in:
parent
3365403814
commit
4d7fe58ec3
66
rtenets
66
rtenets
|
@ -100,7 +100,7 @@ gitea() {
|
||||||
|
|
||||||
local method="$1"
|
local method="$1"
|
||||||
local request="$2"
|
local request="$2"
|
||||||
curl -X "${request}" -H "Content-Type: application/json" -H "Authorization: token ${TOKEN}" "${ENDPOINT}/${method}"
|
\curl -X "${request}" -H "Content-Type: application/json" -H "Authorization: token ${TOKEN}" "${ENDPOINT}/${method}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ----------------- Git commands -----------------------
|
# ----------------- Git commands -----------------------
|
||||||
|
@ -145,8 +145,44 @@ init_repo() {
|
||||||
\git init
|
\git init
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create required files
|
# Make bash script stub
|
||||||
create_tenet_file_tree() {
|
script_stub() {
|
||||||
|
local script_name="$1"
|
||||||
|
local start_phrase="$2"
|
||||||
|
|
||||||
|
if ! [ -f "${script_name}" ]; then
|
||||||
|
mkdir -p "$(dirname "${script_name}")"
|
||||||
|
cat << STUB > "${script_name}"
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
main() {
|
||||||
|
printf "${start_phrase}\\n" 1>&2
|
||||||
|
# put code here
|
||||||
|
}
|
||||||
|
|
||||||
|
main "\$@"
|
||||||
|
STUB
|
||||||
|
chmod +x "${script_name}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Fetch licence
|
||||||
|
fetch_licence() {
|
||||||
|
local licence="COPYING"
|
||||||
|
|
||||||
|
if ! [ -f "${licence}" ]; then
|
||||||
|
if has_command curl; then
|
||||||
|
info "setting licence to GPL by default, see https://www.gnu.org/licenses for more options"
|
||||||
|
\curl "https://www.gnu.org/licenses/gpl-3.0.txt" > "${licence}"
|
||||||
|
else
|
||||||
|
warning "please choose a free software licence, see https://www.gnu.org/licenses"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create README
|
||||||
|
create_readme() {
|
||||||
local readme="README.md~"
|
local readme="README.md~"
|
||||||
|
|
||||||
if ! [ -f "${readme}" ]; then
|
if ! [ -f "${readme}" ]; then
|
||||||
|
@ -169,7 +205,7 @@ Here are the dependencies to build and run the code:
|
||||||
Here is how to run the code:
|
Here is how to run the code:
|
||||||
|
|
||||||
\`\`\`
|
\`\`\`
|
||||||
<make_all_figures>
|
./make_all_figures
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
@ -177,27 +213,27 @@ Here is how to run the code:
|
||||||
Here is how to run the tests:
|
Here is how to run the tests:
|
||||||
|
|
||||||
\`\`\`
|
\`\`\`
|
||||||
<run_all_tests>
|
./tests/run_all_tests
|
||||||
\`\`\`
|
\`\`\`
|
||||||
READMEMSG
|
READMEMSG
|
||||||
|
|
||||||
info "wrote '${readme}'"
|
info "wrote '${readme}'"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
create_authors_file() {
|
||||||
if ! [ -f AUTHORS ]; then
|
if ! [ -f AUTHORS ]; then
|
||||||
printf "%s\\n" "${USER} <${EMAIL}> ${AFFILIATION}" > AUTHORS
|
printf "%s\\n" "${USER} <${EMAIL}> ${AFFILIATION}" > AUTHORS
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
local licence="COPYING"
|
# Create required files
|
||||||
|
create_tenet_file_tree() {
|
||||||
if ! [ -f "${licence}" ]; then
|
create_readme
|
||||||
if has_command curl; then
|
create_authors_file
|
||||||
info "setting licence to GPL by default, see https://www.gnu.org/licenses for more options"
|
fetch_licence
|
||||||
curl "https://www.gnu.org/licenses/gpl-3.0.txt" > "${licence}"
|
script_stub tests/run_all_tests "Running all tests..."
|
||||||
else
|
script_stub make_all_figures "Generating figures..."
|
||||||
warning "please choose a free software licence, see https://www.gnu.org/licenses"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create git repository
|
# Create git repository
|
||||||
|
|
Loading…
Reference in New Issue