Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invocables: Update --help information #754

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"docstring",
"docstrings",
"dscs",
"edkii",
"esrt",
"etree",
"executables",
Expand Down
14 changes: 11 additions & 3 deletions edk2toolext/edk2_invocable.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
!!! warning
This Invocable should only be subclassed if creating a new invocable
"""
def __init__(self) -> None:
"""Init the Invocable."""
super().__init__()
self.PlatformSettings = None

@classmethod
def collect_python_pip_info(cls: 'Edk2Invocable') -> None:
Expand Down Expand Up @@ -389,7 +393,11 @@
Finally, parses all known args and then reads the unknown args in to build vars.
"""
# first argparser will only get settings manager and help will be disabled
settingsParserObj = argparse.ArgumentParser(add_help=False)
settingsParserObj = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=self.AddParserEpilog(),
)

settingsParserObj.add_argument('-h', '--help', dest="help", action="store_true",
help='show this help message and exit')
Expand Down Expand Up @@ -431,8 +439,8 @@
except (FileNotFoundError):
if settingsArg.help:
try:
print("WARNING: Some command line arguments may be missing. Provide a PLATFORM_MODULE file to "
"ensure all command line arguments are present.\n")
print("WARNING: Some command line arguments and possible values for arguments may be missing. "

Check warning on line 442 in edk2toolext/edk2_invocable.py

View check run for this annotation

Codecov / codecov/patch

edk2toolext/edk2_invocable.py#L442

Added line #L442 was not covered by tests
"Provide a PLATFORM_MODULE file to ensure all command line arguments are present.\n")
self.AddCommandLineOptions(settingsParserObj)
except Exception:
pass
Expand Down
18 changes: 14 additions & 4 deletions edk2toolext/invocables/edk2_multipkg_aware_invocable.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,24 @@ def __init__(self) -> None:
def AddCommandLineOptions(self, parserObj: argparse.ArgumentParser) -> None:
"""Adds command line options to the argparser."""
# This will parse the packages that we are going to update
pkg_options = ""
arch_options = ""
target_options = ""
if self.PlatformSettings:
pkg_options = f' \n[{",".join(self.PlatformSettings.GetPackagesSupported())}]'
arch_options = f' \n[{",".join(self.PlatformSettings.GetArchitecturesSupported())}]'
target_options = f' \n[{",".join(self.PlatformSettings.GetTargetsSupported())}]'

parserObj.add_argument('-p', '--pkg', '--pkg-dir', dest='packageList', type=str,
help='Optional - A package or folder you want to update (workspace relative).'
'Can list multiple by doing -p <pkg1>,<pkg2> or -p <pkg3> -p <pkg4>',
help='CSV of EDKII packages / folder containing packages to operate on. '
f'{pkg_options}',
action="append", default=[])
parserObj.add_argument('-a', '--arch', dest="requested_arch", type=str, default=None,
help="Optional - CSV of architecture requested to update. Example: -a X64,AARCH64")
help='CSV of architectures to operate on.'
f'{arch_options}')
parserObj.add_argument('-t', '--target', dest='requested_target', type=str, default=None,
help="Optional - CSV of targets requested to update. Example: -t DEBUG,NOOPT")
help='CSV of targets to operate on.'
f'{target_options}')

def RetrieveCommandLineOptions(self, args: argparse.Namespace) -> None:
"""Retrieve command line options from the argparser ."""
Expand Down
38 changes: 22 additions & 16 deletions edk2toolext/invocables/edk2_platform_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
class Edk2PlatformBuild(Edk2Invocable):
"""Invocable that performs some environment setup,Imports UefiBuilder and calls go."""

def __init__(self) -> None:
"""Init the Invocable."""
super().__init__()
self.PlatformBuilder = None

def AddCommandLineOptions(self, parserObj: argparse.ArgumentParser) -> None:
"""Adds command line options to the argparser."""
# PlatformSettings could also be a subclass of UefiBuilder, who knows!
Expand Down Expand Up @@ -86,22 +91,23 @@
epilog = super().AddParserEpilog()
custom_epilog = ""

variables = self.PlatformBuilder.SetPlatformDefaultEnv()
if any(variables):
max_name_len = max(len(var.name) for var in variables)
max_desc_len = min(max(len(var.description) for var in variables), 55)

custom_epilog += "CLI Env Variables:"
for v in variables:
# Setup wrap and print first portion of description
desc = wrap(v.description, max_desc_len,
drop_whitespace=True, break_on_hyphens=True, break_long_words=True)
custom_epilog += f"\n {v.name:<{max_name_len}} - {desc[0]:<{max_desc_len}} [{v.default}]"

# If the line actually wrapped, we can print the rest of the lines here
for d in desc[1:]:
custom_epilog += f"\n {'':<{max_name_len}} {d:{max_desc_len}}"
custom_epilog += '\n\n'
if self.PlatformBuilder:
variables = self.PlatformBuilder.SetPlatformDefaultEnv()
if any(variables):
max_name_len = max(len(var.name) for var in variables)
max_desc_len = min(max(len(var.description) for var in variables), 55)

Check warning on line 98 in edk2toolext/invocables/edk2_platform_build.py

View check run for this annotation

Codecov / codecov/patch

edk2toolext/invocables/edk2_platform_build.py#L97-L98

Added lines #L97 - L98 were not covered by tests

custom_epilog += "CLI Env Variables:"
for v in variables:

Check warning on line 101 in edk2toolext/invocables/edk2_platform_build.py

View check run for this annotation

Codecov / codecov/patch

edk2toolext/invocables/edk2_platform_build.py#L100-L101

Added lines #L100 - L101 were not covered by tests
# Setup wrap and print first portion of description
desc = wrap(v.description, max_desc_len,

Check warning on line 103 in edk2toolext/invocables/edk2_platform_build.py

View check run for this annotation

Codecov / codecov/patch

edk2toolext/invocables/edk2_platform_build.py#L103

Added line #L103 was not covered by tests
drop_whitespace=True, break_on_hyphens=True, break_long_words=True)
custom_epilog += f"\n {v.name:<{max_name_len}} - {desc[0]:<{max_desc_len}} [{v.default}]"

Check warning on line 105 in edk2toolext/invocables/edk2_platform_build.py

View check run for this annotation

Codecov / codecov/patch

edk2toolext/invocables/edk2_platform_build.py#L105

Added line #L105 was not covered by tests

# If the line actually wrapped, we can print the rest of the lines here
for d in desc[1:]:
custom_epilog += f"\n {'':<{max_name_len}} {d:{max_desc_len}}"
custom_epilog += '\n\n'

Check warning on line 110 in edk2toolext/invocables/edk2_platform_build.py

View check run for this annotation

Codecov / codecov/patch

edk2toolext/invocables/edk2_platform_build.py#L108-L110

Added lines #L108 - L110 were not covered by tests

return custom_epilog + epilog

Expand Down