Say, I want to develop a standalone, compiled application; after reading about various options, I settled on creating a project via
Now, I have a project structure with
Project.toml files, and the program entry point under
At this very moment, all the program does is parse command line arguments; let’s say
MyProgram.jl looks like this:
This minimal program:
- compiles fine with
- runs from the command line just fine and correctly processes command line arguments
What are the steps that I need to take to end up at the REPL with the correct environment, so that I can easily edit my program and test it over and over? Meaning, without having to re-start Julia?
In particular, I would like to change the “comand line arguments” (while in REPL) and call main() over and over.
There may be a way to do what you want, but when faced with this problem in the past, I have changed the structure of the code to make REPL work simpler.
# This function is the top-level of the program's functionality
# and is easily called from the REPL
# Argument parsing happens here, this returns a parsed args structure
# that can be passed to do_stuff()
args = parse_args()
args manually get tedious, it is often helpful to write some tools to create a starting point, I often create a
test/REPL_tests.jl that has functions to mock up useful sets of
args and then
includet that file.
If you want to change the command line arguments while Julia is running, you can edit the variable
Trying to assign a value to the variable probably won’t do what you want, but this should work:
append!(ARGS, ["foo", "--bar"])
For an example:
julia> using ArgMacros
julia> function main()
@argumentflag verbose "-v"
@positionaldefault Int 1 x
main (generic function with 1 method)
julia> append!(ARGS, ["3", "-v"])
julia> push!(ARGS, "4")