leapp/0001-cli-Add-possibility-to-specify-aliases-for-CLI-optio.patch
Petr Stodulka e544327064 IPU 9.8 -> 10.2: CTC1 candidate 1
- Bump leapp-framework to 6.2
- Add possibility to specify aliases for CLI option
- Update test plans for IPU 9.8 -> 10.2
- Resolves: RHEL-128269
2025-11-13 15:42:47 +01:00

121 lines
4.5 KiB
Diff

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 1/3] 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.51.1