Skip to content

Commit

Permalink
[libdnf, actions plugin] Support for "plugin.version" variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jrohel committed Nov 8, 2023
1 parent 18eeb39 commit 03c2a50
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/libdnf5_plugins/actions.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Each non-comment line defines an action and consists of five items separated by
The following variables in the command will be substituted:

* ``${pid}`` - process ID
* ``${plugin.version}`` - version of the actions plugin (added in version 0.3.0)
* ``${conf.<option_name>}`` - option from base configuration
* ``${var.<variable_name>}`` - variable
* ``${tmp.<actions_plugin_variable_name>}`` - variable exists only in actions plugin context
Expand Down
5 changes: 5 additions & 0 deletions libdnf5-plugins/actions/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ std::pair<std::string, bool> Actions::substitute(
std::optional<std::string> var_value;
if (var_name == "pid") {
var_value = std::to_string(getpid());
} else if (var_name.starts_with("plugin.")) {
auto plugin_key = var_name.substr(7);
if (plugin_key == "version") {
var_value = fmt::format("{}.{}.{}", PLUGIN_VERSION.major, PLUGIN_VERSION.minor, PLUGIN_VERSION.micro);
}
} else if (var_name.starts_with("conf.")) {
auto config_opts = base.get_config().opt_binds();
auto it = config_opts.find(std::string(var_name.substr(5)));
Expand Down

0 comments on commit 03c2a50

Please sign in to comment.