trevorld / r-argparse

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

double quote at the end of help strings causes error in argparse version 2.2.1 #46

Closed oliverdrechsel closed 1 year ago

oliverdrechsel commented 1 year ago

Running argparse 2.2.1 we encountered an error in one of our scripts. Scripts work fine with argparse 2.1.6.

Our old code fails with new argparse version.


parser$add_argument('--listlab', type='character', help='This is a helpstring,"Containing Quotes"')
args <- parser$parse_args()

Error in "argparse::parse_args_output(output)" : version requested:
  File "<stdin>", line 19
    parser.add_argument("""--listlab""", type=str, help="""This is a helpstring,,"Containing Quotes"""")
                                                                                                                                                                                                 ^
SyntaxError: EOL while scanning string literal
In addition: Warning message:
In if (grepl("^\\{|^\\[", output)) { :
  the condition has length > 1 and only the first element will be used

Need to add a "whitespace" in the end of the help string.

parser$add_argument('--listlab', type='character', help='This is a helpstring,"Containing Quotes" ')
args <- parser$parse_args()

It seems that the regular expression needs some attention beyond my regex skills....

cheers

trevorld commented 1 year ago

Looks like this was introduced in https://github.com/trevorld/r-argparse/commit/f22b70c46c33798c0703f30547fd99ea4eea0d1b (when I added support for description/epilogue with newlines). I guess I can detect if the last character is a " and if so either escape it or wrap with ''' instead of """...

trevorld commented 1 year ago