Giter Club home page Giter Club logo

easyoptions's People

Contributors

renatosilva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

easyoptions's Issues

Crashes on single quotes in comments

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 ...

Ignore double-hash comments after help text

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.

Allow arbitrary printing 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

Allow empty parameters strings

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;

Boolean options followed by a tab dont get parsed

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).
```

Script could not run on OSX

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.

Hook for translating help text

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.