Comments (4)
Alright. So you are right in observing that catch_all
always means "zero or more additional arguments". I haven't considered a situation where it might need to be required.
For now, you can work around it like so:
# src/bashly.yml
name: update
help: Update one or more package
version: 0.1.0
catch_all: packages
# src/root_command.sh
packages=${other_args[*]}
count=${#other_args[@]}
if [[ $count -eq 0 ]]; then
echo "Please provide at least one package"
exit 1
else
echo "updaging $count packages"
for package in $packages; do
echo "$package"
done
fi
Of course, this is less ideal since the usage text implies that these extra params (PACKAGES
in our case), is optional:
Usage:
update [PACKAGES...]
Let me think about it a little, perhaps it can be easy to implement it in the hash notation of the catch_all
.
Keep this issue open, I will post again if I can implement it without introducing undesired complexity.
from bashly.
Found another option that might be suitable:
# src/bashly.yml
name: update
help: Update one or more package
version: 0.1.0
catch_all: true
args:
- name: package
help: Package name
required: true
# src/root_command.sh
packages=(${args[package]} ${other_args[*]})
count=${#packages[@]}
echo "updaging $count packages"
for package in ${packages[@]}; do
echo "$package"
done
# output
$ ./update -h
update - Update one or more package
Usage:
update PACKAGE [...]
...
With this we create one required argument, one nameless catch_all
, so the usage text looks reasonable, and we merge them in the code.
I will still look for a way to support required catch_all
, but it seems to be more involved than I hoped.
from bashly.
So, I have implemented it. Using required: true
in the hash form of the catch_all
directive will now work as expected.
- The catch-all-advanced example was updated accordingly
- Version 0.6.4 was released to rubygems and dockerhub
- The documentation was updated
from bashly.
@JakobGM - can I close this?
from bashly.
Related Issues (20)
- Presence of `header.sh` breaks executable HOT 5
- How to access permanent environment variable in ./zshrc or ./bashrc HOT 3
- Automation Tools
- test/approve template missing HOT 3
- How can I install this on CentOS ? HOT 1
- Allow flags for commands that have subcommands HOT 20
- Flags not shown in help
- Is there a way to add alias "help" to fixed_flags_filter ? HOT 5
- Is there a way to put cli_usage to custom header? HOT 1
- Dafault environment_variables should be accessible in initialize script HOT 3
- Send errors to stderr HOT 7
- Upgrade template & utility functions HOT 3
- Only commands can be imported? HOT 4
- Is there a way to create global flags? HOT 11
- Issues with `normalize_input` and `catch_all` HOT 14
- Ambiguous error messages HOT 8
- Make invalid `expose` warn instead of error HOT 8
- Error when splitting configuration in sub/nested commands HOT 5
- Alias a command to a subcommand HOT 20
- Ambiguous error messages HOT 11
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 bashly.