Skip to content

Commit

Permalink
Docs: Update command template page
Browse files Browse the repository at this point in the history
- Add a section heading for each file
- Move filenames to listing captions
- Make integration instructions into a section, and add a CAUTION
  admonishment that plugin authors should ignore it
- Link from caution message to next template (DNF5 Plugin Template)
  • Loading branch information
ferdnyc committed Jan 8, 2025
1 parent 4a5e437 commit d58e7e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
34 changes: 27 additions & 7 deletions doc/templates/template-command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,41 @@ This page focuses on how to write a command with two options in dnf5.
the snippets, following the directory structure and naming shown above
each one.

``dnf5/command/template.hpp``

The command header
------------------

.. literalinclude:: command/template.hpp
:language: c++
:linenos:
:caption: ``dnf5/command/template.hpp``

``dnf5/command/template.cpp``
The command source
------------------

.. literalinclude:: command/template.cpp
:language: c++
:linenos:
:caption: ``dnf5/command/template.cpp``

``dnf5/command/arguments.hpp``
The argument class(es)
----------------------

.. literalinclude:: command/arguments.hpp
:language: c++
:linenos:
:caption: ``dnf5/command/arguments.hpp``

Direct integration into dnf5 codebase
-------------------------------------

.. CAUTION::

If you are writing an external command to be included in a dnf5
plugin, **STOP** here and move on to the :ref:`dnf5 plugin template`.
The remainder of this page is only applicable when writing commands
to be included directly in the dnf5 codebase (in the ``dnf5/commands/``
subdirectory).

The command must be included and registered in ``dnf5/main.cpp``

Expand All @@ -36,8 +54,9 @@ The command must be included and registered in ``dnf5/main.cpp``
// new commands must be included in main.cpp
#include "commands/template/template.hpp"
// commands must be registered like this
register_subcommand(std::make_unique<TemplateCommand>(*this), software_management_commands_group);
// commands are registered in the add_commands() function
context.add_and_initialize_command(
std::make_unique<TemplateCommand>(context));
Following this example you should have an output like this.

Expand All @@ -49,13 +68,14 @@ Following this example you should have an output like this.
install Install software
upgrade Upgrade software
...
template A command that prints its name and arguments' name
template A command that prints its name and arguments'
name
.. code-block::
$ dnf5 template --help
Usage:
dnf5 template [GLOBAL OPTIONS] [OPTIONS] [ARGUMENTS]
dnf5 template [GLOBAL OPTIONS] template [ARGUMENTS]
Options:
--bar print bar
Expand Down
2 changes: 2 additions & 0 deletions doc/templates/template-dnf5-plugin.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _dnf5 plugin template:

DNF5 Plugin Template
====================

Expand Down

0 comments on commit d58e7e2

Please sign in to comment.