Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separating different positional arguments #72

Open
musjj opened this issue Aug 9, 2023 · 1 comment
Open

Separating different positional arguments #72

musjj opened this issue Aug 9, 2023 · 1 comment

Comments

@musjj
Copy link

musjj commented Aug 9, 2023

I'm trying to separate positional arguments from extra arguments, like this:

#!/usr/bin/env bash

help="
  Usage:
    cli [<args>...] [--] [<extra-args>...] 
"

docopts --no-declare -A args -h "$help" : "$@"

But running ./cli.sh pos -- extra will print this:

args['--']=false
args['<args>,0']='pos'
args['<args>,1']='--'
args['<args>,2']='extra'
args['<args>,#']=3
args['<extra-args>,#']=0

All of the positional arguments are consumed by <args>. How do I separate them?

@Sylvain303
Copy link
Collaborator

Hello @musjj

The parsing library is still the default docopt (without S) lib. So this is a limitation of the actual parser. See:

docopt/docopt#333

docopt/docopt#190

Until I move to another parser with more power full capability it can't be solved as is. Unfortunately I'm not working actively on the new parser actually. 🤷

You can think for work around though:

./cli.sh :

#!/usr/bin/env bash
help="
  Usage:
    cli <args>... [--other=<extra-args>...]
"

docopts --no-declare -A args -h "$help" : "$@"

output

 ./cli.sh pos pos2 --other=extra1
args['--other,0']='extra1'
args['--other,#']=1
args['<args>,0']='pos'
args['<args>,1']='pos2'
args['<args>,#']=2

Two arguments for --extra

./cli.sh pos pos2 --other=extra1 --other=extra2

XY problem, may be, what are you trying to accomplish?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants