From d6e3548d4a4ca02d2e306c20d8c77881439641dc Mon Sep 17 00:00:00 2001 From: Sebastian Mohr Date: Sun, 24 Aug 2025 11:21:47 +0200 Subject: [PATCH] Formatting commands --- docs/dev/plugins/commands.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/dev/plugins/commands.rst b/docs/dev/plugins/commands.rst index 6a9727859..f39578f11 100644 --- a/docs/dev/plugins/commands.rst +++ b/docs/dev/plugins/commands.rst @@ -1,23 +1,28 @@ .. _add_subcommands: Add Commands to the CLI -~~~~~~~~~~~~~~~~~~~~~~~ +======================= Plugins can add new subcommands to the ``beet`` command-line interface. Define the plugin class' ``commands()`` method to return a list of ``Subcommand`` objects. (The ``Subcommand`` class is defined in the ``beets.ui`` module.) Here's an example plugin that adds a simple command: -:: +.. code-block:: python from beets.plugins import BeetsPlugin 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): print("Hello everybody! I'm a plugin!") + + my_super_command.func = say_hi + class SuperPlug(BeetsPlugin): def commands(self): 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`` and ``--format``. This feature is versatile and extensively documented, try ``pydoc beets.ui.CommonOptionsParser`` for more information. -