From ea960be59b8a4e4ae1c82b68f6d24324dd63374e Mon Sep 17 00:00:00 2001 From: oboulle <olivier.boulle@inria.fr> Date: Thu, 14 Apr 2022 16:38:21 +0200 Subject: [PATCH] updated parsing --- dna_add.sh | 30 +++++++++++++++--------------- dna_create.sh | 24 ++++++++++++------------ dna_del.sh | 32 +++++++++++++++++++++++++------- dna_list.sh | 7 ++++--- dna_quick_complete_test.sh | 2 +- dna_workflow.sh | 2 +- 6 files changed, 58 insertions(+), 39 deletions(-) diff --git a/dna_add.sh b/dna_add.sh index beadae6..04d4df8 100755 --- a/dna_add.sh +++ b/dna_add.sh @@ -9,9 +9,9 @@ source "$project_dir"/workflow_commands/log_manager.sh #load the log manager scr help_function() { echo "" - echo "Usage: dna_add Cname Dname [-nocd]" - echo -e "\tCname : path to the container" - echo -e "\tDname : path to the document" + echo "Usage: dna_add container document [-nocd]" + echo -e "\tcontainer : path to the container" + echo -e "\tdocument : path to the document" echo -e "\t-nocd : turn off channel encoding" echo "" exit 1 # Exit script after printing help @@ -42,18 +42,18 @@ channel_coding=true #-----------------------------------------------# while [[ "$#" -gt 0 ]]; do - case "$1" in - -nocd ) channel_coding=false ; shift ;; - -h | --help ) help_function ; exit 1 ;; - -* ) echo "unknown parameter $1" ; exit 1 ;; - * ) if test -z "${container_path:-}" ; then - container_path="${1}" ; shift ; - elif test -z "${document_path:-}" ; then - document_path="${1}" ; shift ; - else - echo "unknown parameter $1" ; exit 1 ; - fi ;; - esac + case "$1" in + -nocd ) channel_coding=false ; shift ;; + -h | --help ) help_function ; exit 1 ;; + -* ) echo "unknown parameter $1" ; exit 1 ;; + * ) if test -z "${container_path:-}" ; then + container_path="${1}" ; shift ; + elif test -z "${document_path:-}" ; then + document_path="${1}" ; shift ; + else + echo "unknown parameter $1" ; exit 1 ; + fi ;; + esac done if test -z "${container_path:-}" diff --git a/dna_create.sh b/dna_create.sh index ce384b6..b1d5c05 100755 --- a/dna_create.sh +++ b/dna_create.sh @@ -8,11 +8,11 @@ source "$project_dir"/workflow_commands/metadata_manager.sh #load the xml manage help_function() { echo "" - echo "Usage: dna_create [-sim] [-fl int] [-sp string] Cname" + echo "Usage: dna_create [-sim] [-fl int] [-sp string] container" echo -e "\t-sim : turn on simulator mode" echo -e "\t-fl : specify fragment length [default = 100]" echo -e "\t-sp : specify spacer [default = AAAAAAAACCCCCCCC]" - echo -e "\tCname : name of the container" + echo -e "\tcontainer : name of the container" echo "" exit 1 # Exit script after printing help } @@ -26,15 +26,15 @@ spacer="AAAAAAAACCCCCCCC" ######### ====== read parameters ====== ######### #-----------------------------------------------# -while true; do - case "$1" in - -sim ) simulation=true ; shift ;; - -fl ) frag_length=$2 ; shift 2 ;; - -sp ) spacer=$2 ; shift 2 ;; - -h | --help ) help_function ; exit 1;; - -* ) echo "unknown parameter $1" ; exit 1;; - * ) container_name="${1}" ; break ;; - esac +while [[ "$#" -gt 0 ]]; do + case "$1" in + -sim ) simulation=true ; shift ;; + -fl ) frag_length=$2 ; shift 2 ;; + -sp ) spacer=$2 ; shift 2 ;; + -h | --help ) help_function ; exit 1;; + -* ) echo "unknown parameter $1" ; exit 1;; + * ) container_name="${1}" ; break ;; + esac done int_regex='^[0-9]+$' @@ -49,7 +49,7 @@ then echo "error: spacer ($spacer) is not a dna sequence" ; exit 1 fi -if test -z "$container_name" +if test -z "${container_name:-}" then echo "container name missing" help_function diff --git a/dna_del.sh b/dna_del.sh index 67dcd58..3ae9568 100755 --- a/dna_del.sh +++ b/dna_del.sh @@ -8,8 +8,8 @@ source "$project_dir"/workflow_commands/metadata_manager.sh #load the xml manage help_function() { echo "" - echo "Usage: dna_del Cname DI" - echo -e "\tCname : path to the container" + echo "Usage: dna_del container DI" + echo -e "\tcontainer : path to the container" echo -e "\tDI : index of the document to delete" echo "" exit 1 # Exit script after printing help @@ -19,12 +19,30 @@ help_function() { ######### ====== read parameters ====== ######### #-----------------------------------------------# -container_path="${1}" -doc_index="${2}" +while [[ "$#" -gt 0 ]]; do + case "$1" in + -h | --help ) help_function ; exit 1 ;; + -* ) echo "unknown parameter $1" ; exit 1 ;; + * ) if test -z "${container_path:-}" ; then + container_path="${1}" ; shift ; + elif test -z "${doc_index:-}" ; then + doc_index="${1}" ; shift ; + else + echo "unknown parameter $1" ; exit 1 ; + fi ;; + esac +done -if [ "$#" != 2 ] +if test -z "${container_path:-}" then - echo "error invalid number of arguments" + echo "container path missing" + help_function + exit 1 +fi + +if test -z "${doc_index:-}" +then + echo "document index missing" help_function exit 1 fi @@ -37,7 +55,7 @@ fi if [ ! -d "$container_path"/$doc_index ] then - echo "error : $container_path does not contain a document of index $doc_index" + echo "error : container $container_path does not contain a document of index $doc_index" exit 1 fi diff --git a/dna_list.sh b/dna_list.sh index a032fa5..6dbaba0 100755 --- a/dna_list.sh +++ b/dna_list.sh @@ -12,19 +12,20 @@ source "$project_dir"/workflow_commands/metadata_manager.sh #load the xml manage help_function() { echo "" - echo "Usage: dna_list Cname" - echo -e "\tCname : path to the container" + echo "Usage: dna_list container" + echo -e "\tcontainer : path to the container" echo "" exit 1 # Exit script after printing help } -container_path="${1}" if [ "$#" != 1 ] then echo "error invalid number of arguments" help_function exit 1 +else + container_path="${1}" fi if [ ! -d "$container_path" ] diff --git a/dna_quick_complete_test.sh b/dna_quick_complete_test.sh index 809c9b9..604591d 100755 --- a/dna_quick_complete_test.sh +++ b/dna_quick_complete_test.sh @@ -27,7 +27,7 @@ rm -rf "$container_path" "$commands_dir"/dna_create.sh -sim -fl 100 "$container_path" -call_function "$commands_dir"/dna_add.sh -nocd "$commands_dir"/documents_test/doc.txt "$container_path" +call_function "$commands_dir"/dna_add.sh -nocd "$container_path" "$commands_dir"/documents_test/doc.txt #call_function "$commands_dir"/dna_add.sh -nocd "$commands_dir"/documents_test/img_50.png "$container_path" diff --git a/dna_workflow.sh b/dna_workflow.sh index daafe13..ef06ffb 100755 --- a/dna_workflow.sh +++ b/dna_workflow.sh @@ -60,7 +60,7 @@ fi call_function "$commands_dir"/dna_create.sh -sim -fl 100 "$container_path" #TODO fl -call_function "$commands_dir"/dna_add.sh "$document_path" "$container_path" +call_function "$commands_dir"/dna_add.sh "$container_path" "$document_path" call_function "$commands_dir"/dna_store.sh "$container_path" -- GitLab