docopt / docopts

Shell interpreter for docopt, the command-line interface description language.
Other
494 stars 53 forks source link

Separating different positional arguments #72

Open musjj opened 11 months ago

musjj commented 11 months ago

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 commented 11 months ago

Hello @musjj

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

https://github.com/docopt/docopt/issues/333

https://github.com/docopt/docopt/issues/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. :shrug:

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?