python - Docopt accepts multi args in middle? -


i want script accepts command line args "cp" command does:

''' usage: cp.py <source>... <directory> cp.py -t <directory> <source>... cp.py -s <source>... -t <directory> ''' 

those command line

$ python cp.py src/path/1 src/path/2 target/path $ python cp.py -t target/path src/path/1 src/path/2 $ python cp.py -s src/path/1 src/path/2 -t target/path 

will same result:

{'<source>':['src/path/1', 'src/path/2'],'<directory>': 'target/path'} 

thx much. , sorry english:)

currently not supported

you not 1 dreaming of such feature, see docopt issue #190 repeating positional arguments followed single positional argument

ambiguity of repeating argument followed option

options following repeating positional argument make parsing ambiguous. imagine file, having same name command option - how specify , expect result?

proposed alternatives (changing command line design)

i assume, prefer place target directory end make intuitive user.

repeated options values

usage:     cp.py  (-s <source>)... -t <directory> 

this allows 1 target directory , multiple source.

put repeated argument last one

usage:     cp.py <directory> <source>... 

this breaks preference of target being last one, quite easy.

conclusions

  • current docopt not support style, cp using. 1 reason is not easy, cp sometime complex , ambiguous.
  • using repeated argument followed options tricky, try avoid that.
  • options optional, using options, required contradicting rule easy use command line programs.
  • currently, preference using target argument first positional 1 followed repeated source positional arguments.
  • it nice, if docopt allow multiple positional argument followed fixed set of positional arguments, not implemented.

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -