kotlin-argparser icon indicating copy to clipboard operation
kotlin-argparser copied to clipboard

InvalidArgumentName when argument name has trailing digit

Open srki-lendup opened this issue 6 years ago • 2 comments

val url1 by parser.storing(help = "jdbc url. Example: jdbc:postgresql://localhost:5432/db1")

results in:

Exception in thread "main" java.lang.IllegalArgumentException: URL1 is not a valid argument name

Not sure if this is by design or a bug. Changing to the following fixes the issue:

val url_1 by parser.storing(help = "jdbc url. Example: jdbc:postgresql://localhost:5432/db1")

srki-lendup avatar Aug 15 '18 01:08 srki-lendup

I started to fix this bug, but after looking at the tests realized that this was intentional behavior. I encountered this issue when trying to implement a parser.stored() call with the arg --s3-bucket. Since this is a perfectly reasonable arg name, I think this design decision might warrant reconsideration. I'd be happy to submit a pull request if you agree that it makes sense. Thanks.

bzdzb avatar Oct 23 '18 23:10 bzdzb

@bzdzb from looking at where ARG_NAME_RE is defined, I suspect that this was not actually intentional. Instead of $ARG_INITIAL_CHAR_CLASS+, $ARG_INITIAL_CHAR_CLASS$ARG_CHAR_CLASS* would probably make more sense.

I'm also thinking that it may make sense to require $ARG_INITIAL_CHAR_CLASS after a ..

So these should be valid:

url1
url_1
url-1
http_url1
http_url_1
http_url-1
http-url1
http-url_1
http-url-1
http.url1
http.url_1
http.url-1
http_url_1_host
http_url_1-host
http_url-1_host
http_url-1-host
http_url1_host
http_url1-host
http-url_1_host
http-url_1-host
http-url-1_host
http-url-1-host
http-url1_host
http-url1-host
http.url_1_host
http.url_1-host
http.url-1_host
http.url-1-host
http.url1_host
http.url1-host

but these should be invalid:

3com
3_com
3-com
3.com
http_url.1
http-url.1
http.url.1
http_url.1_host
http_url.1-host
http-url.1_host
http-url.1-host
http.url.1_host
http.url.1-host
-url
_url
url_
url-
.url
url.

If you'd be willing to make a PR, I'd really appreciate it.

xenomachina avatar Oct 24 '18 00:10 xenomachina