1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
.. _command template:
DNF5 Command Template
=====================
This page focuses on how to write a command with two options in dnf5.
.. note::
This code is thought to be self explanatory. You should be able to copy
the snippets, following the directory structure and naming shown above
each one.
The command header
------------------
.. literalinclude:: command/template.hpp
:language: c++
:linenos:
:caption: ``dnf5/command/template.hpp``
The command source
------------------
.. literalinclude:: command/template.cpp
:language: c++
:linenos:
:lines: 3-
:caption: ``dnf5/command/template.cpp``
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``
.. code-block:: cpp
// new commands must be included in main.cpp
#include "commands/template/template.hpp"
// 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.
.. code-block::
$ dnf5 --help
...
Software Management Commands:
install Install software
upgrade Upgrade software
...
template A command that prints its name and arguments'
name
.. code-block::
$ dnf5 template --help
Usage:
dnf5 [GLOBAL OPTIONS] template [OPTIONS]
Options:
--bar print bar
--foo print foo
|