0

I'm trying to use docopt so a user can do an input like:

python3 -p argum1 -d argum2 [-u arg_facul]

the arguments argum1 and argum must not be positional; the first two arguments are required and the third is optional.

I already have this:

""" 
Usage:
         pyprogram.py    (-p PASS | --pass=PASS) (-d DICT | --dict=DICT) [-u USER --user=USER]  

    Arguments:


    Options:
        -p              demand argument 1
        -d              demand argument 2 
        -u              may have this agrument or not
"""

The output is:

...$ python3 pyprogram.py -d dict.txt -p passwd.txt -u root 
{'--dict': None,  '--pass': None,  '-d': True,  '-p': True,  '-u': True,  'DICT': 'passwd.txt', 'PASS': 'dict.txt', 'USER': 'root'}

and I want the output to be:

... $ python3 pyprogram.py -d dict.txt -p passwd.txt -u root 
{'--dict': None,  '--pass': None,  '-d': True,  '-p': True,  '-u': True,  'DICT': 'dict.txt',  'PASS': 'passwd.txt', 'USER': 'root'}
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

I have foun out. Docopt is very piky concerning the space ant tabs.

so here is how it's going to be.

"""
Usage:
  passcrack_end.py -p <passw> -d <dic> [-u <user>]

Arguments:
  <passw>   ficheiro onde se encontram as passwords encriptadas - shadow
  <dic>     ficheiros com o dicionario das possiveis palavras passe 
  <user>    Utilizador para o qual quer encontrar a password

Option:
  -p pp     opção obrigatória
  -d dd     opção obrigatória
  -u uu     campo facultativo
"""

Watch out for the spaces. in the options the indentations is 2 spaces -d

if you call the program with this argumentes:

-d derivation -p panto -u ume

the output will be:

{
  "-d": "derivation", 
  "-p": "panto", 
  "-u": "ume"
}

if you call the program with this argumentes:

 -p panto -u ume -d derivation

the output will be the same:

{
  "-d": "derivation", 
  "-p": "panto", 
  "-u": "ume"
}