From 791bc7589cdc87c9580b7fe3075d0488be0a2dc5 Mon Sep 17 00:00:00 2001 From: Christophe Chaudier <christophe@lydra.fr> Date: Fri, 2 Apr 2021 19:41:33 +0200 Subject: [PATCH] feat: print usage --- mygb.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/mygb.sh b/mygb.sh index b4887b4..0319d11 100755 --- a/mygb.sh +++ b/mygb.sh @@ -15,4 +15,71 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. -echo "Hello World !" +# Constant +readonly USAGE=' +mygb.sh <command> [options] \n + \n +Command : \n +init : create the configuration file \n +export : export from GitLab \n +import : import to GitLab \n + \n +Options : \n + -h : print help \n + -c path/to/conf : read one config file \n + -p path/to/projet : export the projet \n + -g path/to/group : export the group and is subgroups and projects \n + -a : export all my group and subgroup \n +' + +# Vars +config_file='.mygb_config' +export_all=false + +_help() { + echo -e "${USAGE}" + exit 1 +} + +_load_config() { + if [[ -e ${config_file} ]]; then + # shellcheck disable=SC1090 + source ${config_file} + else + _create_config + fi +} + +_create_config() { + echo "There is no file!" + + echo "What is the GitLab URL :" + read -r gitlab_url + + echo "What is the GitLab API token :" + read -rs gitlab_api_token + + echo "gitlab_url=\"${gitlab_url}\"" >${config_file} + echo "gitlab_api_token=\"${gitlab_api_token}\"" >>${config_file} + + echo "The file ${config_file} was created with this content." + echo "Please add the line below on your .gitignore" + echo "${config_file}" +} + +main() { + echo "My GitLab Backup" + while getopts c:p:g:ah flag; do + case "${flag}" in + c) config_file=${OPTARG} ;; + p) project=${OPTARG} ;; + g) groups=${OPTARG} ;; + a) export_all=true ;; + h | *) _help ;; + esac + done + + _load_config +} + +main "$@" -- GitLab