Comments (3)
Hi Sven,
what you want, is options that can be called > 1. This is not easy because of the way the options are parsed in bashew:
--config [value]
is parsed into a $config variable, not an array.
A possible solution would be to allow --config:1 [value] --config:2 [value]
syntax which would then be parsed into an array.
Me, I currently use comma-separated values e.g. --effect dark,blur,grain
in pforret/splashmark, but you're right that it doesn't work well for file names.
It's a good suggestion, let me think on that one!
from bashew.
First off, kudos to you, @pforret, for creating such a wonderful project! The amount of effort you've put in really shines through.
Secondly, I'm quite possibly showing my own ignorance here as I don't know the intricacies of how Bashew does parameter parsing, but why, in this case, it isn't possible to simply define an array variable for a given parameter and append to it while going over the parameters?
Here's a simple working example outside of Bashew that on the face of it seems to work:
#!/usr/bin/env bash
script_name=$(basename "${BASH_SOURCE[0]}")
script_ver='0.0.1'
usage() {
cat << EOF
Usage: ${script_name} [-h | --help] [-v | --verbose] [-V | --version]
Example script to demonstrate for optional list options.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
-V, --version Print version number and exit
-c, --config-file Configuration file(s) to be consumed
Example: ${script_name} -c file1.yml -c file2.yml
Example: ${script_name} --config-file file1.yml --config-file file2.yml
EOF
exit
}
config_files=()
while :; do
case "$1" in
-h | --help) usage ;;
-v | --verbose)
set -x
export SHELLOPTS
;;
-V | --version) echo "$script_ver" && exit ;;
-c | --config-file)
config_files+=("$2")
shift
;;
?*)
echo "Unexpected parameter: '${1}'"
usage
;;
*) break ;;
esac
shift
done
for file in "${config_files[@]}"; do
echo "Working with file: ${file}"
done
from bashew.
Hi @usrme ,
you are exactly right that the implementation should be done with bash arrays - config_files+=("$2")
It's a bit more involved in bashew because I use just 1 function list_options()
to define all flags/options/parameters and all usage info/variable initialisation/parsing is derived from there. I just implemented this in bashew version 1.13.0
(the 'normal' template)
Hi @spalberg ,
I did it the following way: there is now an option type 'list' that is by default an empty array and that you can call multiple times: --file /path/file1 --file /path/file2
and that you can use after automatic parsing as an bash array ${file[@]}
Thanks for the suggestion and I hope this makes bashew even better for your usage!
Peter
from bashew.
Related Issues (15)
- bashew installed with basher: `which` shows location of binary, not of package HOT 1
- Proof of concept | Request for comments HOT 2
- automatic bash_completion script generation
- Handle git >= v2.35.2 with wrapper function after CVE-2022-24765 HOT 3
- Str:lower and others don't work out of the box on MacOS HOT 4
- [Question] Why have you prefixed the name of some functions ? HOT 1
- unbound variable HOT 1
- [Question] For what purpose in the function "Os:follow_link()" lines: HOT 6
- .env issue HOT 1
- BUG: Installation from basher cannot find installation directory HOT 6
- bashew cannot handle path to script HOT 2
- Self update
- Do not call `check_last_version` if no `.git` directory found HOT 1
- Add `bashew diag` to print details for bug report 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 bashew.