Code Monkey home page Code Monkey logo

bash-argument-parser's People

Contributors

moebrowne avatar

Stargazers

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

Watchers

 avatar  avatar

bash-argument-parser's Issues

Definable Argument Types

Add the ability to define what the type/format of an argument is, for example you could define an argument to only be valid if its only numbers or at least 4 characters long or even better match a regex pattern

Argument arrays

Add the ability to turn an argument into an array when its repeatedly passed.
For example --set 1 --set 2 --set 3 would cause argValue 'set' to return (1,2,3) as an array

Usage Argument Ordering

Currently the order of the arguments in the usage output is somewhat arbitrary need to order A-Z.

Best way to approach it may be to get all the keys of the argument associative array order them using sort then loop over each one

Default Values

Add the functionality to give arguments a default value

Include help argument by default

A common pattern is to define the -h and --help arguments to show the argument usage, it would be useful if this was included by default maybe with an opt out.

Implementation would look something like this:

argExpected['h|help']="showHelp; Show this help message"

argPassed 'showHelp' && { echo "$(argList)"; exit 0; }

Does not work in a function

argument parser doesn't work when executed from a function.

_arguments() {
  # Define the expected arguments
  declare -A argExpected
  argExpected['h|help']="help - print this message"
  argExpected['debug']="debug - enable debugging"
  argExpected['o|option']="option - some option"

  source argument-parser.sh
}
_main() {
  _arguments "$@"
  argPassed 'debug' && _debug
  argPassed 'help' && _print_help
  _script "$@"
}

Tests Should Make Use Of Exit Codes

Currently when the tests run there is no programmatic way to tell if they passed or not, they should return a 0 exit code if all is okay and a non-zero otherwise

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.