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 #108 from RedHatProductSecurity/refactor-profiles
Browse files Browse the repository at this point in the history
refactor profiles so we can enumerate them properly eg. change 'all' …
  • Loading branch information
JimFuller-RedHat authored Mar 20, 2023
2 parents fe9e60a + ee9deeb commit b038dd4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
12 changes: 12 additions & 0 deletions griffon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ def get_config():
griffon_config = get_config()


def get_config_option(section, option, default_value=None):
if griffon_config.has_option(section, option):
return griffon_config.get(section, option)
if default_value:
return default_value
return None


def list_config_sections():
return griffon_config.sections()


class CorgiService:
name = "component-registry"
description = "Red Hat component registry"
Expand Down
13 changes: 8 additions & 5 deletions griffon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import click
import click_completion

from griffon import griffon_config, print_version
from griffon import get_config_option, list_config_sections, print_version

from .commands.configure import configure_grp
from .commands.docs import docs_grp
Expand Down Expand Up @@ -102,23 +102,26 @@ def plugins_grp(ctx):
"--format",
"-f",
type=click.Choice([el.value for el in OUTPUT_FORMAT]),
default=griffon_config.get("default", "format"),
default=get_config_option("default", "format", "text"),
help="Result format (default is text format).",
)
@click.option(
"-v",
"verbose",
count=True,
default=griffon_config.getint("default", "verbosity"),
default=get_config_option("default", "verbosity", 0),
help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).",
) # noqa
@click.option("--no-progress-bar", is_flag=True, help="Disable progress bar.")
@click.option("--no-color", is_flag=True, help="Disable output of color ansi esc sequences.")
@click.option(
"--profile",
"profile",
type=click.Choice(["cloud", "openshift", "middleware", "latest", "all"]),
default=griffon_config.get("default", "profile"),
type=click.Choice(list_config_sections()),
default=get_config_option(
"default",
"profile",
),
help="Activate profile, defined in .griffonrc.",
)
@click.pass_context
Expand Down
6 changes: 3 additions & 3 deletions griffon/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,11 @@ def cprint(
show_count: bool = True,
):
"""handle format and output"""
from griffon import griffon_config
from griffon import get_config_option

exclude_products = None
if ctx.obj["PROFILE"] != "all":
exclude_products = griffon_config.get(ctx.obj["PROFILE"], "exclude").split("\n")
if ctx.obj["PROFILE"] != "default":
exclude_products = get_config_option(ctx.obj["PROFILE"], "exclude").split("\n")

output = raw_json_transform(data, show_count)
if ctx and ctx.obj["NO_COLOR"]:
Expand Down
2 changes: 1 addition & 1 deletion griffon/static/default_griffonrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[default]
format = text
history_log = ~/.griffon/history.log
profile = all
profile = default
verbosity = 0

[client]
Expand Down

0 comments on commit b038dd4

Please sign in to comment.