renatosilva / easyoptions Goto Github PK
View Code? Open in Web Editor NEWEasy option parsing for Ruby and Bash.
License: Other
Easy option parsing for Ruby and Bash.
License: Other
A line such as the following is not handled by EasyOptions:
## @script.name --set=switch-applications-backward "'<Shift><Super>Tab', '<Shift><Alt>Tab'"
It fails with the error message /home/carlerik/dev/dotfiles/utils/scripts/easyoptions.sh: line 45: Super: No such file or directory
See the fix implemented in fatso83/dotfiles@6300259 for a fix to a doc string that was due to easyoptions not handling the single quotes. This makes it impossible to have examples with embedded quotes, as you can see from this line: fatso83/dotfiles@6300259#diff-9c48148cc281ecbcddc2e236257e924bR28. This is actually the second time in a row I have been bitten by this bug, but I had already forgotten about it by the last time ...
From what I understand, easyoptions follows the same principle as docopt: describe your scripts options in the help text and let easyoptions create the parser for the script.
Unfortunately easyoptions searches the complete script code for ##
comments, not just the first contiguous block ("Docstring" in Python terminology). This creates problems because I use ## BLOCK ##
markers in my script to visually mark blocks in my scripts. Easyoptions considers these part of the help text.
My script requires a parameter, but at the moment there seemed no clean way to show the help output instead of the rather pedantic "Parameters required - try --help". This is what I started with:
if [[ ${#arguments[@]} -ne 1 ]]; then
parse_documentation
echo "${documentation}"
exit
fi
I've now added this function to the top of easyoptions, just after the parse_documentation
definition:
show_documentation() {
[[ -z "$documentation" ]] && parse_documentation
echo "$documentation"
[[ -z $1 ]] || exit
}
so my user code can now be:
if [[ ${#arguments[@]} -ne 1 ]]; then
show_documentation andExit
fi
or:
if [[ ${#arguments[@]} -ne 1 ]]; then
show_documentation
die "Error: At least 1 argument is required."
fi
Of course, if you pass anything to the show_documentation
function, it will exit. I've just been doing a lot of smalltalk programming lately... I also changed the final section of easyoptions to take advantage of that function, so the documentation is only 'shown' in one place to make maintenance easier (e.g. if parse_documentation
was to change):
# Help option
if [[ -n "$help" ]]; then
show_documentation andExit
fi
When using the script with in some situations, we dont have control over the values passed to arguments (e.g: zabbix user parameters. If user pass a empty parameter, zabbix will expand to empty string).
If this cases, the script will report a error.
With this enhacement, user now can specify a flag on option definition (doc or via array):
--myOption=*
In this case, the scirpt will not raise error if user passes a empty string;
Consider following doc chunk (">" is tabs and "." is spaces)
(...)
##
##Options:
##
##>>>--option1=>>>Doctext...
##>>>--option2>>>>Doctext
The option2 is not recognized, because the script consider that after option is a space.
For this work, a hava to do this:
(...)
##
##Options:
##
##>>>--option1=>>>Doctext...
##>>>--option2.>>>>Doctext (put a space before my first tab).
```
OSX use its own sed etc.
Without install gnu sed, the script could not run. It is a good product. I really hope I can have it on OSX without install additional packages.
It would be nice if someone tried to claim a new ruby gem for this, as most forks just float around on GitHub with no chance of being merged. Renato hasn't had a presence on GitHub for the last three years :( https://github.com/renatosilva?tab=overview&from=2016-05-01&to=2017-05-31
It would be nice to have easyoptions use localized ("tranlated") help text. While the main help would be English the help would be localized to your locale settings. See the following snippet from a template in lieu of a patch:
## INTERNATIONALIZATION ##
# - http://www.gnu.org/software/gettext/manual/gettext.html#sh
script=$0
scriptname=$(basename $0)
export TEXTDOMAINDIR=$(dirname $script)/_translations \
TEXTDOMAIN=$scriptname
if which gettext &> /dev/null
then
gettext $HELP
else
printf $HELP
fi
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.