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

How to stop handling options after an argument? #23

Closed
edubart opened this issue Mar 15, 2019 · 3 comments
Closed

How to stop handling options after an argument? #23

edubart opened this issue Mar 15, 2019 · 3 comments

Comments

@edubart
Copy link

edubart commented Mar 15, 2019

I am unable to stop handling option parsing after some argument. This is useful for creating scripts that need to pass arguments when invoking shell commands. For example this sample code does not work as intended:

local argparser = require'argparse'()
argparser:flag('-s --something', "Something flag")
argparser:argument("input", "Input"):action(function()
  argparser:handle_options(false)
end)
argparser:argument("args"):args("*"):action('concat')
local options = argparser:parse()
print(table.concat(options.args, ' '))

When running with lua test.lua -s file a1 a2 -c:

Usage: playground/playground.lua [-s] [-h] <input> [<args>] ...

Error: unknown option '-c'
Did you mean one of these: '-h' '-s'?

What I would expect is when input is consumed the argparser:handle_options(false) would cancel argparser to handle options and the above example would outputs a1 a2 -c.

@edubart edubart closed this as completed Apr 15, 2019
@daurnimator
Copy link

@edubart did you get a solution for this?

@p-ouellette
Copy link

It's not possible to disable option handling after parsing has started.
You could use lua test.lua -s file -- a1 a2 -c instead.

@edubart
Copy link
Author

edubart commented Jun 16, 2019

@daurnimator I made a "hack" by injecting -- into the args just after parsing the first input argument. Not a pretty solution, but worked for me, the code can be seen here:

https://github.com/edubart/euluna-lang/blob/master/euluna/configer.lua#L38

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

No branches or pull requests

3 participants