Command Line Interface Hooks

dnf.cli is a part of DNF that contains code handling the command line tasks for DNF, like for instance dnf install emacs, and outputs the results to the terminal. It is usually of no interest for DNF extension applications, but some parts of it described here can be used by the Plugin Interface to hook up custom commands.

When packaging your custom command, we recommend you to define a virtual provide in the form of Provides: dnf-command(<alias>) in the spec file. See the virtual provides usage for the details.

exception dnf.cli.CliError

Signals a CLI-specific problem (reading configuration, parsing user input, etc.). Derives from dnf.exceptions.Error.

class dnf.cli.demand.DemandSheet

Instances are used to track requests of commands and plugins about how CLI should set up/handle other parts of CLI processing that are not under the command’s/plugin’s direct control. The boolean attributes of the sheet can not be reset once explicitly set, doing so raises an AttributeError.


If True, the dependency solver is allowed to look for solutions that include removing other packages while looking to fulfill the current packaging requests. Defaults to False. Also see dnf.Base.resolve().


If True, during sack creation (sack_activation), download and load into the sack the available repositories. Defaults to False.


If True, at a place where the CLI would otherwise successfully exit, resolve the transaction for any outstanding packaging requests before exiting. Defaults to False.


True informs the CLI that the command can only succeed if the process’s effective user id is 0, i.e. root. Defaults to False.


If True, demand that the CLI sets up the Sack before the command’s run() method is executed. Defaults to False.

Depending on other demands and the user’s configuration, this might or might not correctly trigger metadata download for the available repositories.


If True, DNF will load information about installed packages from the local RPMDB into the sack during dnf.Base.fill_sack(). Defaults to True.


When True, DNF will run entirely from the system cache (equivalent of -C command line option). Defaults to False.


False means that (even expired) cached repository metadata will be used. When True, the expired repository metadata caches are synchronized with server. Defaults to True.


If True, metadata caches for all enabled repositories are forcibly expired before the sack is activated. Defaults to False.


If True, also the repository metadata containing changelogs for packages will be downloaded. Defaults to False.


The return status of the DNF command on success. Defaults to 0.


An additional instance of a subclass of dnf.callback.TransactionProgress used to report information about an ongoing transaction. Defaults to None.

class dnf.cli.Command

Base class of every DNF command.


Sequence of strings naming the command from the command line. Must be a class variable. The list has to contain at least one string, the first string in the list is considered the canonical name. A command name can be contain only letters and dashes providing the name doesn’t start with a dash.


The dnf.Base instance to use with this command.


The dnf.cli.Cli instance to use with this command.


One line summary for the command as displayed by the CLI help.


Command constructor which can be overridden. The constructor is called during CLI configure phase when one of the command’s aliases is parsed from dnf commandline. cli is an instance of dnf.cli.Cli.


Perform any pre-configuration on the command itself and on the CLI. Typically, the command implements this call to set up releasever or enable/disable repository. This method is called before configuration of repos.


Perform any configuration on the command itself and on the CLI. Typically, the command implements this call to set up any demands, tweak the global configuration or the repository configuration. This method is called immediately after the CLI/extension is finished configuring DNF.


Run the command. This method is invoked by the CLI when this command is executed. Should raise dnf.exceptions.Error with a proper message if the command fails. Otherwise should return None. Custom commands typically override this method and put their main work code here.

class dnf.cli.Cli

Manages the CLI, including reading configuration, parsing the command line and running commands.


An instance of DemandSheet, exposed to allow custom commands and plugins influence how the CLI will operate.


Register new command. command_cls is a subclass of Command.

redirect_logger(self, stdout=None, stderr=None):

Change minimal logger level for terminal output to stdout and stderr according to specific command requirements. For stdout and stderr use logging.INFO, logging.WARNING, etc.