Product SiteDocumentation Site

Adding Popt Aliases

Popt provides a powerful library and RPM subsystem for handling the very complex RPM command-line options. You can customize your RPM usage by defining popt aliases for complex command-line arguments to the rpm or rpmbuild commands. A popt alias is a command-line option that expands to other command-line options.
This technique is used internally to define quite a few command-line options to the rpm and rpmbuild commands in terms of other, more complex options. Many of these aliases define simple command-line options in place of more complex query format options.
Cross Reference
Chapter 4, Using the RPM Database covers the query format.
For example, the following entry defines the --requires and –R command-line options to the rpm command:
rpm alias --requires --qf \
--POPTdesc=$"list capabilities required by package(s)"
rpm alias -R --requires
These options are set in the file /usr/lib/rpm/rpmpopt-4.1.
This is specific to RPM 4.1. Other releases of RPM use the same naming format but with the current RPM version number, such as 4.2 and so on.

Defining aliases

Defining aliases is pretty easy. The basic syntax is:
command_name alias option expansion
To create an alias for the rpm command, you use rpm for the command_name.
The command_name must be the name passed to the C poptGetContext function, covered in Chapter 15, Programming RPM with C .
Follow this with alias and then the option. You will need separate aliases for the long and short options. The expansion defines the alias in terms of other already-defined command-line parameters.
You can define some complex aliases, such as the following one to display information about a package:
rpm alias --info --qf 'Name : %-27{NAME} Relocations: %|PREFIXES?{[%{PREFIXES} ]}:{(not relocateable)}|\n\
Version : %-27{VERSION} Vendor: %{VENDOR}\n\
Release : %-27{RELEASE} Build Date: %{BUILDTIME:date}\n\
Install date: %|INSTALLTIME?{%-27{INSTALLTIME:date}}:{(not installed) }| Build Host: %{BUILDHOST}\n\
Group : %-27{GROUP} Source RPM: %{SOURCERPM}\n\
Size : %-27{SIZE}%|LICENSE?{ License: %{LICENSE}}|\n\
Signature : %|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|\n\
%|PACKAGER?{Packager : %{PACKAGER}\n}|\
%|URL?{URL : %{URL}\n}|\
Summary : %{SUMMARY}\n\
Description :\n%{DESCRIPTION}\n' \
--POPTdesc=$"list descriptive information from package(s)"
Popt aliases get evaluated into Linux commands, so you can use pipes and other aspects of Linux shells in your aliases.
Cross Reference
Look closely at the examples in the /usr/lib/rpm/rpmpopt-4.1 file. This is the most complete set of popt alias examples for RPM commands.
You can also define aliases that can set RPM macros, such as the following alias for setting the path to the RPM database:
rpm alias --dbpath --define '_dbpath !#:+'
In this example, !#:+ was defined to behave like a shell history-editing command. With popt, this means to grab the next command-line parameter and place it into the command defined for the alias.
To support the --help and --usage options, you can define the --POPTdesc and --POPTargs options to the alias as shown in the previous examples. These options also support internationalization.
All together, the popt alias setting is very close to the popt option table entries used with the C programming API.
Cross Reference
Chapter 15, Programming RPM with C shows how to program with the popt library.