When you install phy, a command-line tool named phy is installed:

$ phy
Usage: phy [OPTIONS] COMMAND [ARGS]...

  By default, the `phy` command does nothing. Add subcommands with plugins
  using `attach_to_cli()` and the `click` library.

  --version   Show the version and exit.
  -h, --help  Show this message and exit.

This command doesn't do anything by default, but it serves as an entry-point for your applications.

Adding a subcommand

A subcommand is called with phy subcommand ... from the command-line. To create a subcommand, create a new plugin, and implement the attach_to_cli(cli) method. This uses the click library.

Here is an example. Create a file in ~/.phy/plugins/ and write the following:

from phy import IPlugin
import click

class MyPlugin(IPlugin):
    def attach_to_cli(self, cli):
        def hello(name):
            """Display a greeting message."""
            print("Hello %s!" % name)

Then, type the following in a system shell:

$ phy
Usage: phy [OPTIONS] COMMAND [ARGS]...
  hello          Display a greeting message.

$ phy hello world
Hello world!

When the phy CLI is created, the attach_to_cli(cli) method of all discovered plugins are called. Refer to the click documentation to create subcommands with phy.