Skip to content

Add a registry class #105

Open
Open
@lordmauve

Description

@lordmauve

I really like the fact that defopt works without mandatory decorators.

But, practically, I find myself repeatedly writing some small utility that allows using decorators to register subcommands to pass into defopt.run(). My most recent one looks like this:

main = CLI(short={}, parsers=...)

@main.cmd('open')
def open_(target: str, *paths: str):
    ...
    
@main.cmd
def close(target: str):
    ...
    
if __name__ == '__main__':
    main()

The decorator serves as an annotation about which functions are exposed as CLI subcommands, which is handy in a longer file where many of the functions are not exposed.

I think an optional registration utility like this would be a handy thing for defopt to have.

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