Skip to content

Commit ca72e28

Browse files
authored
allow -m to run the entry point in a submodule (#55265)
1 parent 0622123 commit ca72e28

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

base/client.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,12 @@ function exec_options(opts)
292292
invokelatest(show, Core.eval(Main, parse_input_line(arg)))
293293
println()
294294
elseif cmd == 'm'
295-
@eval Main import $(Symbol(arg)).main
295+
entrypoint = push!(split(arg, "."), "main")
296+
Base.eval(Main, Expr(:import, Expr(:., Symbol.(entrypoint)...)))
296297
if !should_use_main_entrypoint()
297298
error("`main` in `$arg` not declared as entry point (use `@main` to do so)")
298299
end
299300
return false
300-
301301
elseif cmd == 'L'
302302
# load file immediately on all processors
303303
if !distributed_mode

test/loading.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,7 @@ end
15841584
@testset "-m" begin
15851585
rot13proj = joinpath(@__DIR__, "project", "Rot13")
15861586
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --project=$rot13proj -m Rot13 --project nowhere ABJURER`) == "--cebwrpg abjurer NOWHERE "
1587+
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --project=$rot13proj -m Rot13.Rot26 --project nowhere ABJURER`) == "--project nowhere ABJURER "
15871588
end
15881589

15891590
@testset "workspace loading" begin

test/project/Rot13/src/Rot13.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,17 @@ function (@main)(args)
1212
return 0
1313
end
1414

15+
module Rot26 # LOL
16+
17+
import ..rot13
18+
19+
rot26(str::AbstractString) = map(rot13 rot13, str)
20+
21+
function (@main)(args)
22+
foreach(arg -> print(rot26(arg), " "), args)
23+
return 0
24+
end
25+
26+
end
27+
1528
end # module Rot13

0 commit comments

Comments
 (0)