Comments (3)
Hi,
Is it this feature that you are talking about?
$ examples/basic.sh --help
Usage: basic.sh [options...] [arguments...]
getoptions basic example
Options:
-a message a
-b message b
-f, +f, --{no-}flag expands to --flag and --no-flag
-v, --verbose e.g. -vvv is verbose level 3
-p, --param PARAM accepts --param value / --param=value
-n, --number NUMBER accepts only a number value
-o, --option[=OPTION] accepts -ovalue / --option=value
-h, --help
--version
$ examples/basic.sh --param
Requires an argument: --param
from getoptions.
Not quite - if I leave out --param
completely, I want it to throw an error. Currently it doesn't do that for me, but I could be missing something.
from getoptions.
I agree with the following opinions.
https://docs.python.org/3/library/optparse.html#what-are-options-for
What are options for?
Options are used to provide extra information to tune or customize the execution of a program. In case it wasn’t clear, options are usually optional. A program should be able to run just fine with no options whatsoever. (Pick a random program from the Unix or GNU toolsets. Can it run without any options at all and still make sense? The main exceptions are find, tar, and dd—all of which are mutant oddballs that have been rightly criticized for their non-standard syntax and confusing interfaces.)
Lots of people want their programs to have “required options”. Think about it. If it’s required, then it’s not optional! If there is a piece of information that your program absolutely requires in order to run successfully, that’s what positional arguments are for.
For this reason, I intentionally did not consider this feature.
I just thought about it a bit and couldn't come up with a way to implement it (without increasing the amount of code significantly). I probably won't add it. I think it's better to make your current code or it a function.
As an alternative, you can improve getoptions
by yourself or create additional modules.
For example, let's add the following code to the end of example/basic.sh
. You will find that you can easily examine the attributes. You can add your own attributes and extend it freely with those attributes.
examples/basic.sh
ext() {
setup() { echo "setup" "$@"; }
msg() { echo "msg" "$@"; }
flag() { echo "flag" "$@"; }
param() { echo "param" "$@"; }
option() { echo "option" "$@"; }
disp() { echo "disp" "$@"; }
"$@"
}
ext parser_definition parse "$0"
output
setup REST plus:true help:usage abbr:true -- Usage: basic.sh [options...] [arguments...]
msg -- getoptions basic example
msg -- Options:
flag FLAG_A -a require:true -- message a
flag FLAG_B -b -- message b
flag FLAG_F -f +f --{no-}flag -- expands to --flag and --no-flag
flag VERBOSE -v --verbose counter:true init:=0 -- e.g. -vvv is verbose level 3
param PARAM -p --param pattern:foo | bar -- accepts --param value / --param=value
param NUMBER -n --number validate:number -- accepts only a number value
option OPTION -o --option on:default -- accepts -ovalue / --option=value
disp :usage -h --help
disp VERSION --version
from getoptions.
Related Issues (20)
- How to implement handler functions for commands with the same name?
- READMEにAURについて追記する HOT 2
- Is there a way to support two layers of sub-commands? HOT 1
- question/help - how to parse to display help (-h) message if there is zero option HOT 1
- No output from gengetoptions embed --overwrite example.sh HOT 2
- Error using gengetoptions parser ./parser_definition.sh parse prog > parser.sh HOT 2
- [Question] Is there any way to ignore not defined option? HOT 1
- Confusion about on: and no: in flag and option HOT 1
- Difference between param and option HOT 3
- Brew upgrade warning HOT 1
- recursion: parse arguments from file HOT 1
- Mandatory/optional parameters HOT 1
- 初期値のバックスラッシュが自動的にエスケープされる HOT 1
- Brew tap ko1nksm/getoptions throws an Error HOT 1
- Missing information about how to use getoptions HOT 1
- support the option grammar
- Fix SC2004
- Support option names with hyphens
- Init attribute for options does not work HOT 3
- Init attribute not working for parameters HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from getoptions.