Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error/warning about "no such option" when 'positional_arguments == TRUE' #34

Closed
greg-minshall opened this issue Mar 12, 2020 · 4 comments
Assignees
Labels

Comments

@greg-minshall
Copy link

greg-minshall commented Mar 12, 2020

hi. thanks for doing these. (as my sister says, "no good deed goes unpunished".)

i may be missing something that's obvious, but in my simple attempt, i don't see optparse complaining about invalid options. i.e., i would think the following would give an error:

  require(optparse)
  options <- list(
    make_option(c("-v", "--verbose"), action="store_true", default=TRUE,
        help="Print extra output [default]")
  )
  p <- OptionParser(option_list=options)
  ## i would think this would fail with s.th. like "unrecognized option"
  args <- parse_args2(p, args=c("-v", "-x", "--foo", "this", "that", "the other"))

the unix shell command, and, lazy that i am to check, i think getopt(3), etc., do:

{1001} getopt abc -x
getopt: invalid option -- 'x'
 --

again, thanks, and sorry if i'm missing the blindingly obvious.

@greg-minshall
Copy link
Author

(sorry about the weird formatting.)

@trevorld trevorld changed the title "invalid option"? No error/warning about "no such option" when 'positional_arguments == TRUE' Mar 12, 2020
@trevorld
Copy link
Owner

I can confirm that currently the optparse package does not throw a warning/error for "invalid options" when positional_arguments == TRUE (as is the case for parse_args2).

I played around with with Python's optparse module and it seems that it does throw an error in such a circumstance with the message "no such option:":

~/tmp$ python test.py -v foo -x
Usage: test.py [options]

test.py: error: no such option: -x

Throwing an error might be a non-reverse-compatible change for certain users but perhaps I should at least try to detect such situations and at least throw a warning instead of simply interpreting them as positional arguments.

@trevorld trevorld self-assigned this Mar 12, 2020
@trevorld trevorld added the bug label Mar 12, 2020
@greg-minshall
Copy link
Author

Trevor, thanks for the reply. maybe a flag to OptionParser() or parse_args() that defaults to the current behavior (with or without a warning), but allows one to choose to have an error thrown if desired?

trevorld added a commit that referenced this issue Mar 28, 2020
…itional_arguments=TRUE``

* Throws an error for unknown short flags and long flags when ``positional_arguments=TRUE`` (#34).
  Thanks Greg Minshall for bug report.

Closes #35.
@greg-minshall
Copy link
Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants