I have a Julia file that takes command line arguments and parses them using ArgParse. I want to run the program in the REPL (trying to debug with Gallium). How do I pass the command line arguments?
Does this work for you?
From the command line:
$ cat test.jl function main(args) @show args end main(ARGS) $ julia test.jl hello world args = String["hello","world"]
From the REPL:
julia> ARGS = ["hello", "world"] include("test.jl") args = String["hello","world"]
Yes, thank you! There is one other change I had to make to accommodate ArgParse.jl
The ArgParse function parse_args(s) parses the command line input with parsing specified by s. I had to instead explicitly pass it ARGS as parse_args(ARGS, s) to use ArgParse in the REPL.
There is that question on StackOverflow. I was wondering if passing arguments as a Collection to
include function is against some ideas behind julia. Because if not, I think it could be a useful feature. As of now you are either required to modify your script with the suggested
isdefined() check or redefine
ARGS explicitly which results in a warning.
I think It would be nice as it would for example streamline using others’ scripts that are not written as modules from within your own ones.
Merging in to duplicate
Let’s suppose the API is
include("script.jl", ARGS=["--foo", "123"]). What would that do?
I couldn’t run my program from the REPL.
When I try this:
julia> ARGS = ["hello", "world"] include("test.jl") error: ERROR: syntax: extra token "include" after end of expression
How can you make it 2 lines:
If I try to run first:
ARGS = ["hello", "world"] Error: ERROR: cannot assign variable Base.ARGS from module main
But command line is working with out any problem