Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide a simpler case $ACTION API through docopts #50

Open
Sylvain303 opened this issue Mar 26, 2021 · 0 comments
Open

provide a simpler case $ACTION API through docopts #50

Sylvain303 opened this issue Mar 26, 2021 · 0 comments

Comments

@Sylvain303
Copy link
Collaborator

use case show_env is listed and not trigered, but create_target_group is remove from action list, but still in the if .. elif .. fi

WARNING: this bash eval at true

v=''
if $v ; then echo pipo; fi
#  will output pipo

example cli (snipet not tested)

# Usage:
#  ./run_migration.sh init
#  ./run_migration.sh add DESCRIPTION MIGRATION_FILE [--target_group=TARGET_GROUP]
#  ./run_migration.sh list
#  ./run_migration.sh run MIGRATION_JOBID
#  ./run_migration.sh delete MIGRATION_JOBID
#  ./run_migration.sh view MIGRATION_JOBID
#  ./run_migration.sh list_target_groups
#  ./run_migration.sh list_available_target
#  ./run_migration.sh list_databases [--server=SERVER_NAME] [--join]
#  ./run_migration.sh show_env
#  ./run_migration.sh -h
#

SCRIPT_DIR=$(dirname $0)
PATH=$SCRIPT_DIR:$PATH
# auto parse the script header and export ${ARGS[]} mapped argument
# docopts do all the magic parsing argument as defined in the doc header.
source docopts.sh --auto "$@"

## ======================================== main switch for arguments
if ${ARGS[add]}
then
  add_migration "${ARGS[DESCRIPTION]}" "${ARGS[MIGRATION_FILE]}" "${ARGS[--target_group]}"
elif ${ARGS[run]}
then
    if exec_migration_job ${ARGS[MIGRATION_JOBID]}
    then
      echo "migration in progress"
      exit 0
    fi
elif ${ARGS[list]}
then
  list_migration
elif ${ARGS[delete]}
then
  delete_migration_job "${ARGS[MIGRATION_JOBID]}"
elif ${ARGS[view]}
then
  view_migration "${ARGS[MIGRATION_JOBID]}"
elif ${ARGS[list_target_groups]}
then
  list_target_groups
elif ${ARGS[create_target_group]}
then
  create_target_group "${ARGS[TARGET_GROUP]}" "${ARGS[SERVER_NAME]}" DATABASE
elif ${ARGS[list_databases]}
then
  list_databases
elif ${ARGS[list_available_target]}
then
  list_available_target
else
  echo "error: unknown action"
fi 

Could we provide something like:

case ${ARGS[docopts_ACTIONS]} in
   add)
    ;;
   run)
    ;;
   list)
    ;;
   *)
    ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant