Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #179 from RedHatProductSecurity/adjust-text-output
Browse files Browse the repository at this point in the history
GRIF-74 adjust text output
  • Loading branch information
JimFuller-RedHat authored Apr 26, 2023
2 parents 84cc31f + 2844cc0 commit d052090
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Changed
- allow -v at the end of CLI invoke
- prefer nvr for component name in text output
### Added
- added entities component-registry components tree which displays dependency tree

## [0.1.26] - 2023-04-21
### Changed
Expand Down
46 changes: 43 additions & 3 deletions griffon/commands/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from component_registry_bindings.bindings.python_client.api.v1 import v1_components_list
from component_registry_bindings.bindings.python_client.models import Component

from griffon import CorgiService, OSIDBService, progress_bar
from griffon import CorgiService, OSIDBService, get_config_option, progress_bar
from griffon.autocomplete import (
get_component_names,
get_cve_ids,
Expand Down Expand Up @@ -82,10 +82,19 @@ def queries_grp(ctx):
default=False,
help="Return all Products.",
)
@click.option(
"-v",
"verbose",
count=True,
default=get_config_option("default", "verbosity", 0),
help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).",
) # noqa
@click.pass_context
@progress_bar
def get_product_summary(ctx, product_stream_name, strict_name_search, all):
def get_product_summary(ctx, product_stream_name, strict_name_search, all, verbose):
"""get product stream."""
if verbose:
ctx.obj["VERBOSE"] = verbose
if not product_stream_name and not all and not strict_name_search:
click.echo(ctx.get_help())
exit(0)
Expand Down Expand Up @@ -222,6 +231,13 @@ def retrieve_component_summary(ctx, component_name, strict_name_search):
default=False,
help="Search for Components by upstream.",
)
@click.option(
"-v",
"verbose",
count=True,
default=get_config_option("default", "verbosity", 0),
help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).",
) # noqa
@click.pass_context
def get_product_contain_component(
ctx,
Expand All @@ -241,9 +257,12 @@ def get_product_contain_component(
search_redhat,
search_community,
search_upstreams,
verbose,
):
with console.status("griffoning", spinner="line") as operation_status:
"""List products of a latest component."""
if verbose:
ctx.obj["VERBOSE"] = verbose
if not purl and not component_name:
click.echo(ctx.get_help())
click.echo("")
Expand All @@ -261,6 +280,7 @@ def get_product_contain_component(
ctx.params["search_latest"] = True

params = copy.deepcopy(ctx.params)
params.pop("verbose")
params.pop("sfm2_flaw_id")
params.pop("flaw_mode")
params.pop("affect_mode")
Expand Down Expand Up @@ -421,6 +441,13 @@ def get_product_contain_component(
default=False,
help="Strict search, exact match of component name.",
)
@click.option(
"-v",
"verbose",
count=True,
default=get_config_option("default", "verbosity", 0),
help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).",
) # noqa
@click.pass_context
@progress_bar
def get_component_contain_component(
Expand All @@ -432,8 +459,11 @@ def get_component_contain_component(
component_arch,
namespace,
strict_name_search,
verbose,
):
"""List components that contain component."""
if verbose:
ctx.obj["VERBOSE"] = verbose
if not component_name and not purl:
click.echo(ctx.get_help())
exit(0)
Expand Down Expand Up @@ -492,9 +522,19 @@ def get_product_manifest_query(ctx, product_stream_name, ofuri, spdx_json_format
"include_fields": {"type": click.Choice(CorgiService.get_fields(Component))},
},
)
@click.option(
"-v",
"verbose",
count=True,
default=get_config_option("default", "verbosity", 0),
help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).",
) # noqa
@click.pass_context
def get_product_latest_components_query(ctx, product_stream_name, ofuri, **params):
def get_product_latest_components_query(ctx, product_stream_name, ofuri, verbose, **params):
"""List components of a specific product version."""
if verbose:
ctx.obj["VERBOSE"] = verbose
ctx.params.pop("verbose")
if not ofuri and not product_stream_name:
click.echo(ctx.get_help())
exit(0)
Expand Down
15 changes: 11 additions & 4 deletions griffon/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,20 @@ def text_output_products_contain_component(
for name in names:
if not any([match in name for match in exclude_components]):
sources = []
nvr = ""
for item in ps_components:
if item["name"] == name and "sources" in item:
sources.extend(item["sources"])
if item["nvr"]:
nvr = item["nvr"]

root_component = "root component"
if sources:
source_purl = PackageURL.from_string(sources[0]["purl"])
root_component = source_purl.name
dep_name = name.replace(component_name, f"[b]{component_name}[/b]")
dep = f"[white]({dep_name})[/white]"

dep_name = nvr.replace(component_name, f"[b]{component_name}[/b]")
dep = f"[white]({dep_name}, {item['type'].lower()})[/white]"
console.print(
Text(ps, style="magenta b u"),
root_component,
Expand All @@ -275,9 +279,12 @@ def text_output_products_contain_component(
for name in names:
if not any([match in name for match in exclude_components]):
sources = []
nvr = ""
for item in ps_components:
if item["name"] == name and "sources" in item:
sources.extend(item["sources"])
if item["nvr"]:
nvr = item["nvr"]

root_component = "root component"
if sources:
Expand All @@ -286,7 +293,7 @@ def text_output_products_contain_component(
f"{source_purl.name}-{output_version(ctx,source_purl.version)}"
)

dep_name = name.replace(component_name, f"[b]{component_name}[/b]")
dep_name = nvr.replace(component_name, f"[b]{component_name}[/b]")
dep = f"[white]({dep_name}, {item['type'].lower()})[/white]"
console.print(
Text(ps, style="magenta b u"),
Expand Down Expand Up @@ -686,7 +693,7 @@ def text_output_list(ctx, output, format, exclude_components):
row["related_url"],
purl.qualifiers.get("arch"),
)
if ctx.obj["VERBOSE"] == 1:
if ctx.obj["VERBOSE"] > 0:
download_url = ""
if "download_url" in row:
download_url = row["download_url"]
Expand Down
4 changes: 3 additions & 1 deletion griffon/services/core_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class product_stream_summary:

name = "product_stream_summary"
description = "retrieve product_stream summary"
allowed_params = ["strict_name_search", "all", "product_stream_name", "ofuri"]
allowed_params = ["strict_name_search", "all", "product_stream_name", "ofuri", "verbose"]

def __init__(self, params: dict) -> None:
self.corgi_session = CorgiService.create_session()
Expand Down Expand Up @@ -633,6 +633,7 @@ class components_containing_specific_component_query:
"component_arch",
"namespace",
"strict_name_search",
"verbose",
]

def __init__(self, params: dict):
Expand Down Expand Up @@ -672,6 +673,7 @@ class components_containing_component_query:
"component_arch",
"namespace",
"strict_name_search",
"verbose",
]

def __init__(self, params: dict) -> None:
Expand Down

0 comments on commit d052090

Please sign in to comment.