added info feedback

This commit is contained in:
Lucas Frérot 2024-12-31 13:35:47 +01:00
parent e074531163
commit 38eecf81eb
No known key found for this signature in database
GPG Key ID: 03B54A50E3FBA7E8
1 changed files with 20 additions and 10 deletions

30
rtenets
View File

@ -182,7 +182,7 @@ check_git_config() {
# Initialize git repository # Initialize git repository
init_repo() { init_repo() {
check_git_config check_git_config
\git init info "$(\git init)"
} }
# ----------------- Tree commands ----------------------- # ----------------- Tree commands -----------------------
@ -207,6 +207,8 @@ main "\$@"
STUB STUB
chmod +x "${script_name}" chmod +x "${script_name}"
fi fi
info "wrote '${script_name}'"
} }
# Fetch licence # Fetch licence
@ -216,7 +218,8 @@ fetch_licence() {
if ! [[ -f "${licence}" ]]; then if ! [[ -f "${licence}" ]]; then
if has_command curl; then if has_command curl; then
info "setting licence to GPL by default, see https://www.gnu.org/licenses for more options" 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}" \curl -s "https://www.gnu.org/licenses/gpl-3.0.txt" > "${licence}"
info "wrote '${licence}'"
else else
warning "please choose a free software licence, see https://www.gnu.org/licenses" warning "please choose a free software licence, see https://www.gnu.org/licenses"
fi fi
@ -228,8 +231,8 @@ create_readme() {
local readme="README.md~" local readme="README.md~"
if ! [[ -f "${readme}" ]]; then if ! [[ -f "${readme}" ]]; then
local project_name="$(enter "project name: ")" local project_name="$(cond_enter "project name: " PROJECT_NAME)"
local project_desc="$(enter "project short description: ")" local project_desc="$(cond_enter "project short description: " PROJECT_DESC)"
cat << READMEMSG > "${readme}" cat << READMEMSG > "${readme}"
# ${project_name} # ${project_name}
@ -267,6 +270,7 @@ 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
info "wrote 'AUTHORS'"
} }
# Create required files # Create required files
@ -333,7 +337,7 @@ setup_dalembert_gitea() {
local remote_ssh="$(jq '.ssh_url' <<< "${repo_json}")" local remote_ssh="$(jq '.ssh_url' <<< "${repo_json}")"
local remote_http="$(jq '.clone_url' <<< "${repo_json}")" local remote_http="$(jq '.clone_url' <<< "${repo_json}")"
if [[ "$(\git remote | \grep -c '^dalembert$')" == "0" ]]; then if [[ "$(\git remote | \grep -c '^dalembert$' || true)" == "0" ]]; then
\git remote add dalembert "${remote_ssh}" \git remote add dalembert "${remote_ssh}"
info "created remote dalembert with '${remote_ssh}" info "created remote dalembert with '${remote_ssh}"
else else
@ -350,14 +354,19 @@ init-tree() {
declare desc="usage: rtenets init-tree <directory>" declare desc="usage: rtenets init-tree <directory>"
local directory="$1" local directory="$1"
(
cd "${directory}"
init_repo
create_tenet_file_tree
)
} }
init-gitea() { init-gitea() {
true declare desc="usage: rtenets init-gitea <directory>"
} }
init-workflow() { init-workflow() {
true declare desc="usage: rtenets init-workflow <directory>"
} }
# Create git repository # Create git repository
@ -371,14 +380,13 @@ create() {
cd "${repo_name}" cd "${repo_name}"
init_repo init_repo
create_tenet_file_tree create_tenet_file_tree
setup_dalembert_gitea
) )
} }
# Print usage and exit # Print usage and exit
usage() { usage() {
cat <<USAGE cat <<USAGE
usage: $0 [--help,-h] [--version] command [args...] usage: $0 [--help,-h] [--version,-v] command [args...]
Available commands: Available commands:
- create: create and populate a repository - create: create and populate a repository
@ -437,4 +445,6 @@ main() {
"${COMMANDS[${command:-default}]:-${COMMANDS[default]}}" "${other_args}" "${COMMANDS[${command:-default}]:-${COMMANDS[default]}}" "${other_args}"
} }
main "$@" # Avoid executing main if sourced
# https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
(return 0 2&>/dev/null) && main "$@" || true