### Navigation

- index
- modules |
- next |
- previous |
- Mopidy 1.0.2 documentation »
- API reference »

# Commands API

class `mopidy.commands.``Command`

  Command parser and runner for building trees of commands.

  This class provides a wraper around `argparse.ArgumentParser` for handling this type of command line application in a better way than argprases own sub-parser handling.

  `add_argument`(*args, **kwargs)

    Add an argument to the parser.

    This method takes all the same arguments as the `argparse.ArgumentParser` version of this method.

  `add_child`(name, command)

    Add a child parser to consider using.

    Parameters: | name (string) – name to use for the sub-command that is being added.

  `exit`(status_code=0, message=None, usage=None)

    Optionally print a message and exit.

  `format_help`(prog=None)

    Format help for current parser and children.

  `format_usage`(prog=None)

    Format usage for current parser.

  `parse`(args, prog=None)

    Parse command line arguments.

    Will recursively parse commands until a final parser is found or an error occurs. In the case of errors we will print a message and exit. Otherwise, any overrides are applied and the current parser stored in the command attribute of the return value.

    Parameters: | args (list of strings) – list of arguments to parse prog (string) – name to use for program
    Return type: | `argparse.Namespace`

  `run`(*args, **kwargs)

    Run the command.

    Must be implemented by sub-classes that are not simply an intermediate in the command namespace.

  `set`(**kwargs)

    Override a value in the finaly result of parsing.

### Navigation

- index
- modules |
- next |
- previous |
- Mopidy 1.0.2 documentation »
- API reference »