Skip to content

The CLI Object

Sean Collings edited this page Jul 9, 2021 · 2 revisions

The CLI Object

The CLI object is the central way in which you will interact with ARC. It acts as a top-level namespace for all of your commands, and also implements additional functionality pertaining to the entire tool.

Additional Functionality

Example

from arc import CLI

# There are other things you can pass in, but generally you will
# want name and version. Name should be the name of the tool you're making.
# In other words, it should be the same name as one would invoke on the
# command line to execute it. Version is what will be displayed by --version
cli = CLI(name="tool", version="0.1")

@cli.subcommand()
def hello():
    '''Command that prints Hello World'''
    print("Hello, World!")

@hello.subcommand()
def night():
    '''Command to greet people later
    in the day'''
    print("Good evening good sir!")

cli()
$ python example.py hello
Hello, World!

Default Behavior

By default, if you execute a ARC tool without any arguments, it will display the --help info. This can be modulated with the @cli.default decorator.

from arc import CLI

cli = CLI()

@cli.default()
def base():
    print("I'm the default behavior!")

cli()
$ python example.py
I'm the default behavior!

@cli.default's interface is the exact same as @cli.subcommand and as such can have a Command Type, context, and whatever arguments you want.

Clone this wiki locally