Skip to content

Support nested options #119

@acdupont

Description

@acdupont

Would there be interest in some sort of "extended" option that has a similar api as a command, but is treated like an option? The use case I'm interested in is mapping a cli interface to a json configuration file.

A json file such as:

{
  "o1": "o1value",
  "o2": "o2value",
  "extended1": {
    "e1o1": "n1o1value"
  }
}

would have ArgParseSettings such as:

s = ArgParseSettings()

@add_arg_table! s begin
  "--o1"
    action = :store_arg
  "--o2"
    action = :store_arg
  "extended1"
    action = :extended_arg
end

@add_arg_table! s["extended1"] begin
  "e1p1"
    help = "e1p1 positional argument"
    action = :store_arg
  "--e1o1"
    action = :store_arg
end

and would look something like this on the cli:

myprog --o1 o1value extended1 e1p1value --e1o1 e1o1value --o2 o2value

and lastly would result in parsed args:

parsed_args =
 Dict{Symbol, Any} with 5 entries:
   :o1   => "o1value"
   :o2   => "o2value"
   :extended1  => Dict{Symbol, Any}(:e1p1=>"e1p1value", :e1o1=>e1o1value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions