Skip to content

CLI with non primitive types + subcommands #430

@AlejandroBaron

Description

@AlejandroBaron

Hello!

I'm trying to do combine the CLI + config utility with subcommands and i'm not able to.

The CLI takes an object as an argument and in the subcommand it calls an object submethod.

This is a minimal example with 3 files

python example.py --config config.yaml subcommand

myclass.py

class MyClass:

    def __init__(self, x: int):
        self.x = x

    def method(self):
        print(self.x*2)

example.py (entrypoint)

from jsonargparse import CLI
from myclass import MyClass

class MyCLI:

    def __init__(self, myobj: MyClass):

        self.myobj = myobj

    def subcommand(self):
        self.myobj.method()

if __name__ == "__main__":
    CLI(MyCLI)

config.yaml

myobj:
  class_path: myclass.MyClass
  init_args:
    x: 2

Is this not supported yet?

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions