Compare commits

...

1 Commits

Author SHA1 Message Date
Yuriy Kohut
e1caaeaa20 cli: Add possibility to specify aliases for CLI option
Bump the package release
2025-11-14 09:55:23 +02:00
2 changed files with 127 additions and 2 deletions

View File

@ -0,0 +1,120 @@
From e62e4e144670de9337c8a406ff8d532b9c1033d4 Mon Sep 17 00:00:00 2001
From: Matej Matuska <mmatuska@redhat.com>
Date: Fri, 19 Sep 2025 11:39:11 +0200
Subject: [PATCH] cli: Add possibility to specify aliases for CLI option
The existing 'name' and 'short_name' parameters are kept as is for
backwards compatibility.
Also a dest parameter is added for specifying the name of the attribute
to be added to the parsed args object.
The change is backwards compatible, bump framework-version from 6.1 to
6.2.
Jira: RHEL-110563 (related)
---
leapp/utils/clicmd.py | 53 +++++++++++++++++++++++++++++++++++++------
packaging/leapp.spec | 2 +-
2 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/leapp/utils/clicmd.py b/leapp/utils/clicmd.py
index 89d3e27..7f819ea 100644
--- a/leapp/utils/clicmd.py
+++ b/leapp/utils/clicmd.py
@@ -202,9 +202,22 @@ class Command(object):
internal = kwargs.pop('internal', {})
self._options.append((args, kwargs, internal))
- def add_option(self, name, short_name='', help='', # noqa; pylint: disable=redefined-builtin
- is_flag=False, inherit=False, value_type=str, wrapped=None, action=None, metavar=None,
- choices=None, default=None):
+ def add_option( # noqa; pylint: disable=redefined-builtin, too-many-arguments
+ self,
+ name,
+ short_name="",
+ help="",
+ is_flag=False,
+ inherit=False,
+ value_type=str,
+ wrapped=None,
+ action=None,
+ metavar=None,
+ choices=None,
+ default=None,
+ aliases=None,
+ dest=None,
+ ):
"""
Add an option
@@ -230,16 +243,39 @@ class Command(object):
:type choices: list
:param default: default value of the argument if nothing is specified
:type default: any
+ :param aliases: Aliases for the option, appended after short_name and name in help output
+ :type aliases: list[str]
+ :param dest: The name of the attribute to be added to the parsed args object
+ :type dest: str
:return: self
"""
name = name.lstrip('-')
names = ['--' + name]
kwargs = {}
if short_name:
- short_name = short_name.lstrip('-')
- if len(short_name) != 1:
- raise CommandDefinitionError("Short name should be one letter only")
- names.insert(0, '-' + short_name)
+ stripped = short_name.lstrip('-')
+ if len(stripped) != 1:
+ msg = "Short name option should be one letter only (excluding '-'), but received: {}"
+ raise CommandDefinitionError(msg.format(short_name))
+ names.insert(0, '-' + stripped)
+
+ aliases = aliases or []
+ for alias in aliases:
+ if alias.startswith('--'):
+ names.append('--' + alias.strip('-'))
+ elif alias.startswith('-'):
+ stripped = alias.strip('-')
+ if len(stripped) != 1:
+ msg = "Short name option should be one letter only (excluding '-'), but received: {}"
+ raise CommandDefinitionError(msg.format(alias))
+ names.append('-' + stripped)
+ else:
+ # no way to distinguish whether it's a short or long option if no leading dashes,
+ # decide based on length
+ if len(alias) == 1:
+ names.append('-' + alias)
+ else:
+ names.append('--' + alias)
if not action:
action = 'store'
if is_flag:
@@ -252,6 +288,9 @@ class Command(object):
kwargs['choices'] = choices
if default is not None:
kwargs['default'] = default
+ if dest:
+ kwargs['dest'] = dest
+
self._add_opt(*names, help=help, # noqa; pylint: disable=redefined-builtin
action=action, internal={'wrapped': wrapped, 'inherit': inherit}, **kwargs)
return self
diff --git a/packaging/leapp.spec b/packaging/leapp.spec
index bdf5a79..22a2085 100644
--- a/packaging/leapp.spec
+++ b/packaging/leapp.spec
@@ -13,7 +13,7 @@
# This is kind of help for more flexible development of leapp repository,
# so people do not have to wait for new official release of leapp to ensure
# it is installed/used the compatible one.
-%global framework_version 6.1
+%global framework_version 6.2
# IMPORTANT: everytime the requirements are changed, increment number by one
# - same for Provides in deps subpackage
--
2.49.0

View File

@ -37,7 +37,7 @@
Name: leapp
Version: 0.20.0
Release: 1%{?dist}
Release: 1%{?dist}.elevate.1
Summary: OS & Application modernization framework
License: ASL 2.0
@ -65,6 +65,7 @@ Requires: leapp-repository
# PATCHES HERE
# Patch0001: filename.patch
Patch0001: 0001-cli-Add-possibility-to-specify-aliases-for-CLI-optio.patch
%description
Leapp utility provides the possibility to use the Leapp framework via CLI.
@ -161,6 +162,7 @@ Requires: findutils
# APPLY REGISTERED PATCHES HERE
# %%patch -P 0001 -p1
%patch -P 0001 -p1
##################################################
@ -246,9 +248,12 @@ install -m 0644 -p man/leapp.1 %{buildroot}%{_mandir}/man1/
# no files here
%changelog
* Fri Nov 14 2025 Yuriy Kohut <ykohut@almalinux.org> - 0.20.0-1.elevate.1
- Add possibility to specify aliases for CLI options
* Thu Aug 14 2025 Karolina Kula <kkula@redhat.com> - 0.20.0-1
- Rebase to new upstream 0.20.0
- Resolves: RHEL-67625
- Resolves: RHEL-67625
* Wed May 14 2025 Petr Stodulka <pstodulk@redhat.com> - 0.19.0-3
- Rebuild