un outil de sondage - retour accueil
git clone git://bebou.netlib.re/kun
Log | Files | Refs | README |
commit 0fed6f9be3efebb75c75daa5ed282752b9083f3e parent 9a4a15429ec2eed490ee815ba5096478024b82fd Auterice: Arthur Pons <arthur.pons@unistra.fr> Date: Thu, 19 Sep 2024 11:50:45 +0200 Ajout d'un makefile kun.sh devient kun qui est l'exec à copier dans bin commands.sh et utils.sh deviennent des sortes de librairie (dans /usr/local/share/kun, le bon endroit ??) Diffstat:
R | commands -> commands.sh | | | 0 | |
M | kun | | | 22 | +++++++++++----------- |
A | kun.sh | | | 103 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | makefile | | | 22 | ++++++++++++++++++++++ |
R | utils -> utils.sh | | | 0 |
5 files changed, 136 insertions(+), 11 deletions(-)
diff --git a/commands b/commands.sh diff --git a/kun b/kun @@ -6,13 +6,13 @@ while getopts "h" opt;do esac done -. ./utils +. /usr/local/share/kun/utils.sh -. ./commands +. /usr/local/share/kun/commands.sh [ "$help" = "yes" ] \ && { echo "Les commandes dispos : \n" - grep -E -B3 "^[a-zA-Z]+ *\(\) *{ *$" ./commands | grep -v ^$ + grep -E -B3 "^[a-zA-Z]+ *\(\) *{ *$" /usr/local/share/kun/commands | grep -v ^$ exit 0; } @@ -23,14 +23,14 @@ done # Probablement safe mais fastidieux if [ -n "$1" ];then case "$1" in - (create) create "$2" && exit 0 || exit 1;; - (addanswer) addanswer "$2" "$3" && exit 0 || exit 1;; - (modifyanswer) modifyanswer "$2" "$3" && exit 0 || exit 1;; - (deletequestion) deletequestion "$2" && exit 0 || exit 1;; - (deleteanswer) deleteanswer "$2" "$3" && exit 0 || exit 1;; - (results) results "$2" && exit 0 || exit 1;; - (getpeople) getpeople "$2" && exit 0 || exit 1;; - (getanswer) getanswer "$2" "$3" && exit 0 || exit 1;; + (create) create "$2" && exit 0 || exit 1;; + (addanswer) addanswer "$2" "$3" && exit 0 || exit 1;; + (modifyanswer) modifyanswer "$2" "$3" && exit 0 || exit 1;; + (deletequestion) deletequestion "$2" && exit 0 || exit 1;; + (deleteanswer) deleteanswer "$2" "$3" && exit 0 || exit 1;; + (results) results "$2" && exit 0 || exit 1;; + (getpeople) getpeople "$2" && exit 0 || exit 1;; + (getanswer) getanswer "$2" "$3" && exit 0 || exit 1;; (*) _die "Commande n'existe pas";exit 1;; esac fi diff --git a/kun.sh b/kun.sh @@ -0,0 +1,103 @@ +#! /bin/sh + +while getopts "h" opt;do + case $opt in + (h) help=yes;; + esac +done + +. ./utils.sh + +. ./commands.sh + +[ "$help" = "yes" ] \ + && { echo "Les commandes dispos : \n" + grep -E -B3 "^[a-zA-Z]+ *\(\) *{ *$" ./commands | grep -v ^$ + exit 0; + } + +# Probablement pas safe mais pratique +#[ "$(type $1)" = "$1 is a shell function" ] \ +# && { eval "$(echo $@ | cut -d';' -f1)" && exit 0 || exit 1;} + +# Probablement safe mais fastidieux +if [ -n "$1" ];then + case "$1" in + (create) create "$2" && exit 0 || exit 1;; + (addanswer) addanswer "$2" "$3" && exit 0 || exit 1;; + (modifyanswer) modifyanswer "$2" "$3" && exit 0 || exit 1;; + (deletequestion) deletequestion "$2" && exit 0 || exit 1;; + (deleteanswer) deleteanswer "$2" "$3" && exit 0 || exit 1;; + (results) results "$2" && exit 0 || exit 1;; + (getpeople) getpeople "$2" && exit 0 || exit 1;; + (getanswer) getanswer "$2" "$3" && exit 0 || exit 1;; + (*) _die "Commande n'existe pas";exit 1;; + esac +fi + + +while [ ! "$k" = "quitter" ];do + + t="";l="" + k=$(<<-. fzy + quitter + créer un sondage + répondre à un sondage + consulter un sondage + supprimer un sondage + supprimer une réponse + . + ) + + case $k in + ("créer un sondage") + create "$id" ;; + ("répondre à un sondage") + read -p "id du sondage : " id + _questionexists "$id" || { _die "Sondage n'existe pas"; continue; } + l=$(<<-. fzy + ajouter une réponse + modifier une réponse + . + ) + case $l in + ("ajouter une réponse") + read -p "votre nom : " name + while ! addanswer "$id" "$name";do + read -p "votre nom : " name + done ;; + ("modifier une réponse") + read -p "id de la réponse : " idrep + modifyanswer "$id" "$idrep" ;; + esac ;; + ("consulter un sondage") + read -p "id du sondage : " id + _questionexists "$id" || { _die "Sondage n'existe pas"; continue; } + while [ ! "$t" = "quitter" ];do + t=$(<<-. fzy + quitter + toutes + une personne + . + ) + case $t in + ("toutes") + results "$id" ;; + ("une personne") + while [ ! "$pers" = "quitter" ];do + pers=$(getpeople "$id" | sed '1i\quitter' | fzy) + [ "$pers" != "quitter" ] && getanswer "$id" "$pers" + done;pers="";; + esac + done ;; + ("supprimer un sondage") + read -p "id du sondage : " id + deletequestion "$id" ;; + ("supprimer une réponse") + read -p "id du sondage : " id + read -p "id de la réponse : " idrep + deleteanswer "$id" "$idrep";; + esac + +done + diff --git a/makefile b/makefile @@ -0,0 +1,22 @@ +PREFIX = /usr/local + +all: kun + +kun: kun.sh commands.sh utils.sh + < $< sed -E 's,\./utils,/usr/local/share/kun/utils,;s,\./commands,/usr/local/share/kun/commands,' > $@ + +install: + mkdir -p ${PREFIX}/bin + mkdir -p ${PREFIX}/share/kun + chmod +x kun + cp kun ${PREFIX}/bin + cp utils.sh ${PREFIX}/share/kun/ + cp commands.sh ${PREFIX}/share/kun/ + +uninstall: + rm ${PREFIX}/bin/kun + rm ${PREFIX}/share/kun/commands.sh + rm ${PREFIX}/share/kun/utils.sh + rmdir --ignore-fail-on-non-empty ${PREFIX}/share/kun + rmdir --ignore-fail-on-non-empty ${PREFIX}/bin + diff --git a/utils b/utils.sh