Enable the half-implemented -f, --function option#57
Enable the half-implemented -f, --function option#57rqelibari wants to merge 3 commits intodocopt:masterfrom
Conversation
1. When docopts is run inside functions it shall not exit but rather return. 2. Variables should be defined using local.
|
Hi, @rqelibari Thanks for your contribution. Could you also give some bash use-case in #43 on how to use it? On repetitive function call it could be a real performance killer if I'm remember well the multi |
|
Of course. #!/usr/bin/env bash
sayMyName() {
eval "`docopts -f -V - -h - : "$@" <<-USAGE
Usage: $0 <your-name>
----
Version: 1.0
USAGE`"
echo "hello ${your_name}"
}
# Will output 'hello James'
sayMyName James
# This will print 'hello '
echo "hello ${your_name}"
# Will output 'error: Usage: ...'. No 'hello ...' will be printed.
sayMyName
# This line will get executed
echo "Done!"
Regarding the performance question |
When the command does not take any arguments nor options docopt must not print anything out. This is a problem if `docopts` was started with `-f, --function` option, as `docopts` would print out only `local` and that prints out all environment variables instead of setting one.
|
I'll move this conversation/discussion to related issue #43, and we will keep here for PR details. Thanks. I'm a bit busy actually I will review and test it in a next couple of days/week, see my word/thinking in the issue comment (when I'll post it actually in Draft). about the function, the usage syntax is a bit tricky, your proposed full bash syntax activate a lot of bash "dirty tricks" and nested parsing/reading:
Could you think about something more simple? To be continued. |
return.
This PR solves #43.