Compare commits

..

No commits in common. "2e6f71842fad1e735252aa7f03aa8c925ed1d094" and "038424b52630be62f749e1cfaa4d7741d0cb7c4d" have entirely different histories.

1 changed files with 9 additions and 80 deletions

89
rtenets
View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Author: Lucas Frérot
# Affiliation:
# Sorbonne Université, CNRS, Institut Jean Le Rond d'Alembert,
# Sorbonne Université, CNRS, Institut Jean Le Rond dAlembert,
# F-75005 Paris, France
#
# Copyright © 2024 Lucas Frérot
@ -35,7 +35,7 @@ readonly NC='\033[0m'
readonly ENDPOINT="https://git.dalembert.upmc.fr/api/v1"
# Lab info
readonly AFFILIATION="Sorbonne Université, CNRS, Institut Jean Le Rond d'Alembert, F-75005 Paris, France"
readonly AFFILIATION="Sorbonne Université, CNRS, Institut Jean Le Rond dAlembert, F-75005 Paris, France"
# ----------------- Logging commands -----------------------
@ -104,17 +104,17 @@ get_gitea_token(){
else
TOKEN="$(enter "gitea token: ")"
fi
readonly TOKEN
}
gitea() {
check_api_prerequisites
readonly TOKEN
if ! is_set TOKEN; then
get_gitea_token
fi
readonly TOKEN
local method="$1"
local request="$2"
local data=""
@ -172,8 +172,6 @@ init_repo() {
\git init
}
# ----------------- Tree commands -----------------------
# Make bash script stub
script_stub() {
local script_name="$1"
@ -265,8 +263,6 @@ create_tenet_file_tree() {
script_stub make_all_figures "Generating figures..."
}
# ----------------- Gitea commands -----------------------
get_gitea_owner() {
gitea /user GET | jq -r '.login'
}
@ -331,25 +327,9 @@ setup_dalembert_gitea() {
setup_software_heritage_hook "${owner}" "${repo_name}" "${remote_http}"
}
# ----------------- Script subcommands commands -----------------------
init-tree() {
declare desc="usage: rtenets init-tree <directory>"
local directory="$1"
}
init-gitea() {
true
}
init-workflow() {
true
}
# Create git repository
create() {
declare desc="usage: rtenets create <directory>"
create_repo() {
local repo_name="$1"
info "recursively creating directory '${repo_name}'"
mkdir -p "${repo_name}"
@ -358,70 +338,19 @@ create() {
cd "${repo_name}"
init_repo
create_tenet_file_tree
setup_dalembert_gitea
)
}
# Print usage and exit
usage() {
cat <<USAGE
usage: $0 [--help,-h] [--version] command [args...]
Available commands:
- create: create and populate a repository
- init-tree: populate a repository with README, AUTHORS, COPYING and test/
- init-gitea: setup a remote on a gitea server with SoftwareHeritage hook
- init-workflow: setup a Python virtual environment and Snakemake template
- check: verify tenent compliance for a repository
USAGE
}
version() {
cat <<VERSION
rtenets 0.0.1
Copyright © 2024 Lucas Frérot
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions;
VERSION
true
}
main() {
local other_args=()
local help_mode=0
for i in "$@"; do
case $i in
-v|--version)
version
return 0
;;
-h|--help)
help_mode=1
;;
*)
other_args+=("${i}")
;;
esac
done
check_git_config
create_tenet_file_tree
local command="${other_args[0]}"
if [[ "${help_mode}" == 1 ]]; then
type "${command}" | sed -n -e 's/^.*declare desc="\(.*\)";/\1/p'
fi
# Subcommands trick
# https://blogsh.github.io/2020/03/21/subcommands-in-bash-scripts.html
declare -A COMMANDS=(
[default]=usage
[init-tree]=init-tree
[init-gitea]=init-gitea
[init-workflow]=init-workflow
[create]=create
)
"${COMMANDS[${command:-default}]:-${COMMANDS[default]}}" "${other_args}"
gitea /user GET
}
main "$@"