Skip to content

Commit

Permalink
allow -m to run the entry point in a submodule (JuliaLang#55265)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Aug 31, 2024
1 parent 0622123 commit ca72e28
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ function exec_options(opts)
invokelatest(show, Core.eval(Main, parse_input_line(arg)))
println()
elseif cmd == 'm'
@eval Main import $(Symbol(arg)).main
entrypoint = push!(split(arg, "."), "main")
Base.eval(Main, Expr(:import, Expr(:., Symbol.(entrypoint)...)))
if !should_use_main_entrypoint()
error("`main` in `$arg` not declared as entry point (use `@main` to do so)")
end
return false

elseif cmd == 'L'
# load file immediately on all processors
if !distributed_mode
Expand Down
1 change: 1 addition & 0 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,7 @@ end
@testset "-m" begin
rot13proj = joinpath(@__DIR__, "project", "Rot13")
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --project=$rot13proj -m Rot13 --project nowhere ABJURER`) == "--cebwrpg abjurer NOWHERE "
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --project=$rot13proj -m Rot13.Rot26 --project nowhere ABJURER`) == "--project nowhere ABJURER "
end

@testset "workspace loading" begin
Expand Down
13 changes: 13 additions & 0 deletions test/project/Rot13/src/Rot13.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,17 @@ function (@main)(args)
return 0
end

module Rot26 # LOL

import ..rot13

rot26(str::AbstractString) = map(rot13 rot13, str)

function (@main)(args)
foreach(arg -> print(rot26(arg), " "), args)
return 0
end

end

end # module Rot13

0 comments on commit ca72e28

Please sign in to comment.