Coder Social home page Coder Social logo

Comments (4)

DannyBen avatar DannyBen commented on May 24, 2024

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.

DannyBen avatar DannyBen commented on May 24, 2024

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.

DannyBen avatar DannyBen commented on May 24, 2024

So, I have implemented it. Using required: true in the hash form of the catch_all directive will now work as expected.

  1. The catch-all-advanced example was updated accordingly
  2. Version 0.6.4 was released to rubygems and dockerhub
  3. The documentation was updated

from bashly.

DannyBen avatar DannyBen commented on May 24, 2024

@JakobGM - can I close this?

from bashly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.