trevorld / r-argparse

command-line optional and positional argument parser
GNU General Public License v2.0
103 stars 11 forks source link

Detect illegal python construction and pass error to user #11

Closed trevorld closed 9 years ago

trevorld commented 9 years ago

Give user this error message

# test.py
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("M", required=True, help = "Test")
args = parser.parse_args()

trevorld@trevorld-Bonobo-Extreme:~/projects$ python ~/tmp/test.py 
Traceback (most recent call last):
  File "/home/trevorld/tmp/test.py", line 4, in <module>
    parser.add_argument("M", required=True, help = "Test")
  File "/usr/lib/python2.7/argparse.py", line 1265, in add_argument
    kwargs = self._get_positional_kwargs(*args, **kwargs)
  File "/usr/lib/python2.7/argparse.py", line 1377, in _get_positional_kwargs
    raise TypeError(msg)
TypeError: 'required' is an invalid argument for positionals

With this call

library(argparse,quietly = T,verbose=F)
parser <- ArgumentParser()
parser$add_argument('M',required=TRUE,
                   help="Test")
 Args <- parser$parse_args()

Instead of

Error in rjson::fromJSON(paste(output, collapse = "")) : 
  unexpected character 'T'
trevorld commented 9 years ago

Reported by Martí Duran Ferrer