Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matthewdeanmartin/parse_quick_parameters.sh
Provide a documentation string to get named function parameters. Fork of msknapp's. Similar to docopt
https://github.com/matthewdeanmartin/parse_quick_parameters.sh
Last synced: 18 days ago
JSON representation
Provide a documentation string to get named function parameters. Fork of msknapp's. Similar to docopt
- Host: GitHub
- URL: https://github.com/matthewdeanmartin/parse_quick_parameters.sh
- Owner: matthewdeanmartin
- License: mit
- Created: 2024-11-24T18:24:27.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-24T18:24:51.000Z (about 2 months ago)
- Last Synced: 2024-11-24T19:31:52.284Z (about 2 months ago)
- Language: Shell
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# parse_quick_parameters.sh
Provide a documentation string to get named function parameters. Fork of msknapp's. Similar to docopt## Installation
Just copy the file or use package managers.
### Use bkpg
Get [bpkg](https://www.bpkg.sh/).
To get the source version:
```bash
bpkg install matthewdeanmartin/parse_quick_parameters.sh
```To get the hosted version:
```bash
bpkg install parse_quick_parameters
```### Use git-remote-get
This is a fancy way of just downloading git files.
```
pip install git-remote-get
git-remote-get ./ --owner matthewdeanmartin --repo "parse_quick_parameters.sh" deps
```## Usage
```bash
#!/usr/bin/env bash
source deps/parse_quick_parameters/parse_quick_parameters.shfunction do_something_quick {
parse_quick_parameters "my_file=-f|--file,bool:run=-r|--run,name=-n|--name" "$@" || return 0
echo "my file is: $my_file"
echo "my name is: $name"
echo "run is: $run"
}
``````terminal
>> source parse_quick_parameters.sh
>> do_something_quick --name name --run --file file
my file is: file
my name is: name
run is: true
>> do_something_quick "file" "name" --run
my file is: file
my name is: name
run is: true
```## Notes
Shellcheck doesn't understand the pattern and will raise [SC2154](https://github.com/koalaman/shellcheck/wiki/SC2154)
## Alternatives
- [getopts](https://en.wikipedia.org/wiki/Getopts) Builtin bash command
- [docopts](https://github.com/docopt/docopts) Shell version of `docopts`
- [argparse-bash](https://github.com/nhoffman/argparse-bash) Use python's argparse in bash## Contributing
Use `Makefile`. `bats` tests assume `bats` was installed with `npm`.
```
make format lint test
```## Credits
- [msknapp](https://github.com/msknapp/maintainable-bash/blob/master/1_init/3.1_parameters/shortcut.sh#L3)