Formatting commands

This commit is contained in:
Sebastian Mohr 2025-08-24 11:21:47 +02:00 committed by Šarūnas Nejus
parent 1dfd232270
commit d6e3548d4a
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435

View file

@ -1,23 +1,28 @@
.. _add_subcommands: .. _add_subcommands:
Add Commands to the CLI Add Commands to the CLI
~~~~~~~~~~~~~~~~~~~~~~~ =======================
Plugins can add new subcommands to the ``beet`` command-line interface. Define Plugins can add new subcommands to the ``beet`` command-line interface. Define
the plugin class' ``commands()`` method to return a list of ``Subcommand`` the plugin class' ``commands()`` method to return a list of ``Subcommand``
objects. (The ``Subcommand`` class is defined in the ``beets.ui`` module.) objects. (The ``Subcommand`` class is defined in the ``beets.ui`` module.)
Here's an example plugin that adds a simple command: Here's an example plugin that adds a simple command:
:: .. code-block:: python
from beets.plugins import BeetsPlugin from beets.plugins import BeetsPlugin
from beets.ui import Subcommand from beets.ui import Subcommand
my_super_command = Subcommand('super', help='do something super') my_super_command = Subcommand("super", help="do something super")
def say_hi(lib, opts, args): def say_hi(lib, opts, args):
print("Hello everybody! I'm a plugin!") print("Hello everybody! I'm a plugin!")
my_super_command.func = say_hi my_super_command.func = say_hi
class SuperPlug(BeetsPlugin): class SuperPlug(BeetsPlugin):
def commands(self): def commands(self):
return [my_super_command] return [my_super_command]
@ -47,4 +52,3 @@ use it like you would a normal ``OptionParser`` in an independent script. Note
that it offers several methods to add common options: ``--album``, ``--path`` that it offers several methods to add common options: ``--album``, ``--path``
and ``--format``. This feature is versatile and extensively documented, try and ``--format``. This feature is versatile and extensively documented, try
``pydoc beets.ui.CommonOptionsParser`` for more information. ``pydoc beets.ui.CommonOptionsParser`` for more information.