Alternate approach for parsing/threading to subcommands #28

Closed
opened 2020-10-30 00:24:36 +00:00 by decentral1se · 1 comment
Owner

While fiddling with #25, I ran into an issue where sub_app_rm keeps getting selected instead of sub_app_secret_rm based on the (delete|rm) argument which is determined by the logic in the abra function. It's a bit magic in there.

Following the https://github.com/andsens/docopt.sh docs I came up with the following approach for matching parsed CLI input against subcommand functions:

  if [ ${abra_app} ] && [ ${abra_secret} ] && [ ${abra_rm} ]; then
    sub_app_secret_delete ${abra__args_[*]}
    return
  fi

Then we manually iterate out all the matches ourselves. I like our one script approach and not having to manage multiple DOC="..." is a bonus for me. Having to write everything out ourselves is a bit gack but that seems to be the trade-off.

Tried it over at:

b15a214049

While fiddling with https://git.autonomic.zone/coop-cloud/abra/issues/25, I ran into an issue where `sub_app_rm` keeps getting selected instead of `sub_app_secret_rm` based on the `(delete|rm)` argument which is determined by the logic in the `abra` function. It's a bit magic in there. Following the https://github.com/andsens/docopt.sh docs I came up with the following approach for matching parsed CLI input against subcommand functions: ``` if [ ${abra_app} ] && [ ${abra_secret} ] && [ ${abra_rm} ]; then sub_app_secret_delete ${abra__args_[*]} return fi ``` Then we manually iterate out all the matches ourselves. I like our one script approach and not having to manage multiple `DOC="..."` is a bonus for me. Having to write everything out ourselves is a bit gack but that seems to be the trade-off. Tried it over at: > https://git.autonomic.zone/coop-cloud/abra/commit/b15a214049e5a10c36a6228026721824b622bb71
Author
Owner

Existing implementation fixed, onwards!

Existing implementation fixed, onwards!
This repo is archived. You cannot comment on issues.
No Milestone
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: coop-cloud/abra#28
No description provided.