Comments (2)
It's really not complicated. All it does is arrange a handful of variables and format them a little.
It only accepts one argument and it's an error code which gets passed to exit
. In fact, usage
is essentially an alias to exit
plus some documentation.
It's intended to be used like this:
unset OPTIND
while getopts ":h" option; do
case $option in
h) usage 0 ;;
*) usage 1 ;;
esac
done && shift $(($OPTIND - 1))
Or:
some_command_that_may_return_nonzero || usage 1
Here are some examples to show it's full range:
The only way to get any output is to set the script name.
source bashful-messages
SCRIPT_NAME=thingy
usage
Which outputs:
Usage: thingy [OPTIONS]
GENERAL OPTIONS
-h Display this help message.
Adding some more variables:
source bashful-messages
SCRIPT_NAME=thingy
SCRIPT_ARGUMENTS="[key] [value]"
SCRIPT_USAGE="This is a thing that sets a value for the given key."
SCRIPT_DESCRIPTION="Sometimes you want to define a value for some key.
In those instances, you may consider using this command.
At some point, I plan on making this description more detailed."
SCRIPT_EXAMPLES="thingy some_setting on
thingy number_of_things 5
thingy -l
thingy -d some_setting"
SCRIPT_OPTIONS="-d Delete key.
-l List keys."
# for these, if they're set to anything, it will show in usage
INTERACTIVE=0 # interactive is off, but still set
VERBOSE=1 # verbose is on
usage
Will output this:
Usage: thingy [OPTIONS] [key] [value]
This is a thing that sets a value for the given key.
Sometimes you want to define a value for some key.
In those instances, you may consider using this command.
At some point, I plan on making this description more detailed.
EXAMPLES
thingy some_setting on
thingy number_of_things 5
thingy -l
thingy -d some_setting
GENERAL OPTIONS
-h Display this help message.
-i Interactive. Prompt for certain actions.
-f Don't prompt.
-v Be verbose.
-q Be quiet.
APPLICATION OPTIONS
-d Delete key.
-l List keys.
Try removing or changing those values to see the effect. Revisiting this function is reminding me how semi-pointless it is. It's very opinionated, and minimally useful, but it illustrates a way to formalize a style for command line documentation.
from bashful.
Thank you very much @jmcantrell!
from bashful.
Related Issues (12)
- Global overwrite of stdout and stderr HOT 1
- License? HOT 3
- Simple example of how to use functions? HOT 3
- Request: documentation in github HOT 2
- Unable to type on the script HOT 1
- Need few examples usage of flatten_file HOT 1
- Add "suggested" input HOT 1
- Add "multiple" choice HOT 1
- Add default for choice
- Add "multiple" input
- Wrapper for RC != 0 HOT 2
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 bashful.