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

argument parsing: make -- argument terminate parsing #10226

Closed
StefanKarpinski opened this issue Feb 17, 2015 · 10 comments · Fixed by #10726
Closed

argument parsing: make -- argument terminate parsing #10226

StefanKarpinski opened this issue Feb 17, 2015 · 10 comments · Fixed by #10726

Comments

@StefanKarpinski
Copy link
Member

See discussion here: https://groups.google.com/forum/#!topic/julia-users/lahbdoIImcQ

When parsing options to julia encountering a -- argument should terminate option parsing and treat the rest of the arguments as simply part of ARGS.

@jsbee
Copy link

jsbee commented Feb 20, 2015

any update on this?

@jakebolewski
Copy link
Member

-- now terminates argument parsing, but the example highlighted in the google groups issue stil does not work because julia loads foo.jl with arguments bar & baz but then tries to load bar as a source file and fails because bar does not exist. One way to fix this would be to disallow loading a script -L foo.jl and running an additional source file at the same time.

julia -i -L foo.jl -- bar baz

disallowing

julia -i --load=foo.jl source.jl arg1 arg2

@StefanKarpinski
Copy link
Member Author

Perhaps the -i flag should be what forces interactive mode and thus causes arguments to be considered as arguments rather than scripts. Alternately, the -- could signal that everything after it should go verbatim in ARGS – implying that they are not the names of scripts to be loaded.

@jakebolewski
Copy link
Member

The second option will not work because julia --longarg foo -- src.jl is a valid way to write julia --longarg=foo src.jl using getopt style parsing.

@StefanKarpinski
Copy link
Member Author

Says who? Don't we get to dictate what the -- means for parsing options and arguments to julia?

@jakebolewski
Copy link
Member

Unfortunately no if we are using the system getopt library (which we are currently). julia just see's the argument buffer that is left over from command line parsing.

@StefanKarpinski
Copy link
Member Author

Ok, that's annoying, but it also seems reasonable to me that -i should force arguments to go into ARGS instead of being used as scripts. Currently julia script.jl and julia -i script.jl behave the same way except that isinteractive() is false in the former and true in the latter. Might as well make the -i flag a little more useful than that.

@jakebolewski
Copy link
Member

--load doesn't really have to exist. Is it just to save a toplevel require("src.jl") call in a source file?

@tkelman
Copy link
Contributor

tkelman commented Feb 23, 2015

Might as well make the -i flag a little more useful than that.

While I agree that the -i flag currently doesn't serve a whole lot of purpose, encouraging its use more places is not necessarily a good thing... Running a script with -i can easily stop and block for user input, because that's an entirely reasonable thing to do in some places when isinteractive() is true.

@StefanKarpinski
Copy link
Member Author

How about scanning the arguments for -- before even passing them to getopt? That way we're not subject to what getopt thinks that -- should mean, but we can rely on getopt for the rest of the option parsing.

jakebolewski added a commit that referenced this issue Apr 2, 2015
encountering a -- terminates getopt option parsing
and the rest of the options are part of ARGS

closes #10226
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

Successfully merging a pull request may close this issue.

4 participants