Skip to content

cli: Add possibility to specify aliases for CLI option - #910

Merged
karolinku merged 1 commit into
oamg:mainfrom
matejmatuska:commands-options-alias
Oct 8, 2025
Merged

cli: Add possibility to specify aliases for CLI option#910
karolinku merged 1 commit into
oamg:mainfrom
matejmatuska:commands-options-alias

Conversation

@matejmatuska

@matejmatuska matejmatuska commented Sep 19, 2025

Copy link
Copy Markdown
Member

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 the framework-version to 6.2.

Jira: RHEL-110563 (related)


Example help text:

[root@localhost ~]# leapp upgrade --help
usage: leapp upgrade [-h] [--nogpgcheck] [--report-schema {1.0.0,1.1.0,1.2.0}] [--target-os {rhel,centos,almalinux}]
                     [--target TARGET_VERSION] [--iso ISO] [--channel {ga,e4s,eus,aus}] [--enablerepo <repoid>]
                     [--no-rhsm-facts] [--no-insights-register] [--no-rhsm] [--verbose] [--debug]
                     [--enable-experimental-feature Feature] [--whitelist-experimental ActorName] [--reboot]
                     [--resume]

Description:

Upgrade the current system to the next available major version.

Optional arguments:
  -h, --help            show this help message and exit
  --nogpgcheck          Disable RPM GPG checks. Same as yum/dnf --nogpgcheck option.
  --report-schema {1.0.0,1.1.0,1.2.0}
                        Specify report schema version for leapp-report.json
  --target TARGET_VERSION, --target-version TARGET_VERSION                                        <------
                        Specify RHEL version to upgrade to for default detected upgrade flavour

The alias is listed after the name and the argument "hint" (TARGET_VERSION) is created from dest which is target_version.
The option is defined like this:

@command_opt(
    'target',
    help='Specify RHEL version to upgrade to for {} detected upgrade flavour'.format(
        command_utils.get_upgrade_flavour()
    ),
    aliases=['target-version'],
    dest='target_version',
)

@github-actions

Copy link
Copy Markdown

Thank you for contributing to the Leapp project!

Please note that every PR needs to comply with the Leapp Guidelines and must pass all tests in order to be mergeable.
If you want to request a review or rebuild a package in copr, you can use following commands as a comment:

  • review please @oamg/developers to notify leapp developers of the review request
  • /packit copr-build to submit a public copr build using packit

To launch regression testing public members of oamg organization can leave the following comment:

  • /rerun to schedule basic regression tests using this pr build and leapp-repository*main* as artifacts
  • /rerun 42 to schedule basic regression tests using this pr build and leapp-repository*PR42* as artifacts
  • /rerun-sst to schedule sst tests using this pr build and leapp-repository*main* as artifacts
  • /rerun-sst 42 to schedule sst tests using this pr build and leapp-repository*PR42* as artifacts

Please open ticket in case you experience technical problem with the CI. (RH internal only)

Note: In case there are problems with tests not being triggered automatically on new PR/commit or pending for a long time, please consider rerunning the CI by commenting leapp-ci build (might require several comments). If the problem persists, contact leapp-infra.

Comment thread leapp/utils/clicmd.py
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument list is definitely long, maybe we should consider replacing the optional args with **kwargs at this point. I left it as it is for now.

@karolinku

Copy link
Copy Markdown
Member

is there a ticket behind this change?

@pirat89 pirat89 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing bump of leapp-framework

@matejmatuska

matejmatuska commented Sep 22, 2025

Copy link
Copy Markdown
Member Author

is there a ticket behind this change?

@karolinku No dedicated one, it's a prerequisite for this https://issues.redhat.com/browse/RHEL-110563. That's why I didn't add it in the descriptions.

@matejmatuska

Copy link
Copy Markdown
Member Author

missing bump of leapp-framework

Right, completely missed that, thanks.

@pirat89

pirat89 commented Sep 22, 2025

Copy link
Copy Markdown
Member

is there a ticket behind this change?

@karolinku No dedicated one, it's a prerequisite for this https://issues.redhat.com/browse/RHEL-110563. That's why I didn't add it in the descriptions.

well, still it would be nice to have a note about it. e.g. related jira: .....

Comment thread leapp/utils/clicmd.py Outdated
Comment thread leapp/utils/clicmd.py Outdated
Comment thread leapp/utils/clicmd.py Outdated
if len(short_name) != 1:
raise CommandDefinitionError("Short name should be one letter only")
names.insert(0, '-' + short_name)
if aliases:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be good to add validation if aliases is a list and alias a string?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it's not a bad idea, but we don't validate any other types. E.g. if you pass 1 to name it fails too.

@matejmatuska

Copy link
Copy Markdown
Member Author

/rerun

Comment thread leapp/utils/clicmd.py Outdated
@matejmatuska

Copy link
Copy Markdown
Member Author

/packit copr-build

@matejmatuska
matejmatuska force-pushed the commands-options-alias branch from 2951ffa to 4dd038d Compare October 1, 2025 14:13
@matejmatuska

Copy link
Copy Markdown
Member Author

Squashed commits, from my side it's ready to merge :).

@matejmatuska matejmatuska added this to the 8.10/9.8 milestone Oct 1, 2025
@matejmatuska
matejmatuska force-pushed the commands-options-alias branch from 4dd038d to fb1e9c3 Compare October 2, 2025 09:16
@matejmatuska

matejmatuska commented Oct 2, 2025

Copy link
Copy Markdown
Member Author

Added the bump of framework version to the commit message.

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)
@matejmatuska
matejmatuska force-pushed the commands-options-alias branch from fb1e9c3 to 05f5acd Compare October 2, 2025 09:33
@matejmatuska

Copy link
Copy Markdown
Member Author

/rerun

1 similar comment
@matejmatuska

Copy link
Copy Markdown
Member Author

/rerun

@matejmatuska

Copy link
Copy Markdown
Member Author

/packit retest-failed

@karolinku karolinku added the changelog-checked The merger/reviewer checked the changelog draft document and updated it when relevant label Oct 2, 2025
@karolinku

Copy link
Copy Markdown
Member

/rerun

@karolinku
karolinku merged commit e62e4e1 into oamg:main Oct 8, 2025
17 of 20 checks passed
@matejmatuska
matejmatuska deleted the commands-options-alias branch October 9, 2025 08:29
karolinku added a commit to karolinku/leapp that referenced this pull request Feb 10, 2026
## Packaging
- Bump leapp-framework to 6.2 (oamg#910)

## Leapp (tool)
### Enhancements
- Add possibility to specify aliases for CLI option (oamg#910)
@karolinku karolinku mentioned this pull request Feb 10, 2026
pirat89 pushed a commit to karolinku/leapp that referenced this pull request Feb 10, 2026
## Packaging
- Bump leapp-framework to 6.2 (oamg#910)

## Leapp (tool)
### Enhancements
- Add possibility to specify aliases for CLI option (oamg#910)
pirat89 pushed a commit that referenced this pull request Feb 10, 2026
## Packaging
- Bump leapp-framework to 6.2 (#910)

## Leapp (tool)
### Enhancements
- Add possibility to specify aliases for CLI option (#910)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-checked The merger/reviewer checked the changelog draft document and updated it when relevant enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants