comonicon / Comonicon.jl

Your best CLI generator in JuliaLang

Home Page:https://comonicon.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Using optional optional types from Configurations fails with an error.

VPetukhov opened this issue · comments

Describe the bug
Using optional optional types from Configurations fails with an error.

Version of the package:
1.0.0, julia 1.8.3

To Reproduce

module M

using Comonicon
using Configurations

@option struct Opts
    x::String = "x"
end

"""
# Options
- `-c, --config <path/to/option/or/specific field>`: config.
"""
@main function main(;config::Opts=Opts())
    @show config
end

end

M.command_main()

ERROR: KeyError: key :config not found
Stacktrace:
[1] getindex(h::Dict{Symbol, Any}, key::Symbol)
@ Base ./dict.jl:498
[2] command_main(ARGS::Vector{String})
@ Main.M ~/.julia/dev/Comonicon/src/codegen/julia.jl:277
[3] command_main()
@ Main.M ~/.julia/dev/Comonicon/src/codegen/julia.jl:90
[4] top-level scope
@ REPL[2]:1

Expected behavior
The function should show config = Main.M.Opts("x")

Reason
Accessing kwargs in emit_leaf_call assumes that the option was already stored, which happens only for required options (afaik).