Skip to content
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
138 changes: 75 additions & 63 deletions pcs/cli/common/parse_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,75 @@
)
)

MODIFIER_OPTIONS_BOOL: Final[frozenset[str]] = frozenset(
(
"--all",
"--agent-validation",
# TODO remove
# used only in acl commands and it is deprecated there
"--autodelete",
"--brief",
"--config",
"--corosync",
"--debug",
"--defaults",
"--disabled",
"--enable",
"--expired",
"--force",
"--full",
"--quiet",
FUTURE_OPTION,
# TODO remove
# used only in deprecated 'pcs resource|stonith show'
"--groups",
"--hide-inactive",
"--local",
"--monitor",
"--no-default-ops",
"--nodesc",
"--no-expire-check",
"--no-cluster-uuid",
"--no-keys-sync",
"--no-stop",
"--no-strict",
"--no-watchdog-validation",
"--off",
"--overwrite",
"--pacemaker",
"--promoted",
"--safe",
"--show-secrets",
"--simulate",
"--skip-offline",
"--start",
"--strict",
"--yes",
)
)

MODIFIER_OPTIONS_VAL: Final[frozenset[str]] = frozenset(
(
"--after",
"--before",
"--booth-conf",
"--booth-key",
"--corosync_conf",
"--from",
# TODO remove
# used in resource create and stonith create, deprecated in both
"--group",
"--name",
"--node",
"--request-timeout",
"--to",
"--token",
"-f",
"-p",
"-u",
)
)

ARG_TYPE_DELIMITER: Final = "%"

# h = help, f = file,
Expand Down Expand Up @@ -526,75 +595,18 @@ class InputModifiers:
def __init__(self, options: Mapping[str, ModifierValueType]):
self._defined_options = set(options.keys())
self._options = dict(options)
self._options.update(
{opt: opt in options for opt in MODIFIER_OPTIONS_BOOL}
)
self._options.update(
{opt: options.get(opt, None) for opt in MODIFIER_OPTIONS_VAL}
)
self._options.update(
{
# boolean values
"--all": "--all" in options,
"--agent-validation": "--agent-validation" in options,
# TODO remove
# used only in acl commands and it is deprecated there
"--autodelete": "--autodelete" in options,
"--brief": "--brief" in options,
"--config": "--config" in options,
"--corosync": "--corosync" in options,
"--debug": "--debug" in options,
"--defaults": "--defaults" in options,
"--disabled": "--disabled" in options,
"--enable": "--enable" in options,
"--expired": "--expired" in options,
"--force": "--force" in options,
"--full": "--full" in options,
"--quiet": "--quiet" in options,
FUTURE_OPTION: FUTURE_OPTION in options,
# TODO remove
# used only in deprecated 'pcs resource|stonith show'
"--groups": "--groups" in options,
"--hide-inactive": "--hide-inactive" in options,
"--local": "--local" in options,
"--monitor": "--monitor" in options,
"--no-default-ops": "--no-default-ops" in options,
"--nodesc": "--nodesc" in options,
"--no-expire-check": "--no-expire-check" in options,
"--no-cluster-uuid": "--no-cluster-uuid" in options,
"--no-keys-sync": "--no-keys-sync" in options,
"--no-stop": "--no-stop" in options,
"--no-strict": "--no-strict" in options,
"--no-watchdog-validation": (
"--no-watchdog-validation" in options
),
"--off": "--off" in options,
"--overwrite": "--overwrite" in options,
"--pacemaker": "--pacemaker" in options,
"--promoted": "--promoted" in options,
"--safe": "--safe" in options,
"--show-secrets": "--show-secretes" in options,
"--simulate": "--simulate" in options,
"--skip-offline": "--skip-offline" in options,
"--start": "--start" in options,
"--strict": "--strict" in options,
"--yes": "--yes" in options,
# string values
"--after": options.get("--after", None),
"--before": options.get("--before", None),
"--booth-conf": options.get("--booth-conf", None),
"--booth-key": options.get("--booth-key", None),
"--corosync_conf": options.get("--corosync_conf", None),
"--from": options.get("--from", None),
# TODO remove
# used in resource create and stonith create, deprecated in both
"--group": options.get("--group", None),
"--name": options.get("--name", None),
"--node": options.get("--node", None),
OUTPUT_FORMAT_OPTION: options.get(
OUTPUT_FORMAT_OPTION, OUTPUT_FORMAT_VALUE_TEXT
),
"--request-timeout": options.get("--request-timeout", None),
"--to": options.get("--to", None),
"--token": options.get("--token", None),
"--wait": options.get("--wait", False),
"-f": options.get("-f", None),
"-p": options.get("-p", None),
"-u": options.get("-u", None),
}
)

Expand Down
53 changes: 6 additions & 47 deletions pcs_test/tier0/cli/common/test_parse_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from pcs.cli.common.errors import CmdLineInputError
from pcs.cli.common.parse_args import (
MODIFIER_OPTIONS_BOOL,
MODIFIER_OPTIONS_VAL,
ArgsByKeywords,
InputModifiers,
KeyValueParser,
Expand Down Expand Up @@ -621,53 +623,10 @@ class InputModifiersTest(TestCase):
# pylint: disable=too-many-public-methods
def setUp(self):
self.supported = ["a", "b", "c"]
self.bool_opts = [
"--all",
"--autodelete",
"--config",
"--corosync",
"--debug",
"--defaults",
"--disabled",
"--enable",
"--force",
"--full",
# TODO remove
# used only in deprecated 'pcs resource|stonith show'
"--groups",
"--hide-inactive",
"--local",
"--monitor",
"--no-default-ops",
"--no-expire-check",
"--no-strict",
"--no-watchdog-validation",
"--nodesc",
"--off",
"--pacemaker",
"--promoted",
"--safe",
"--simulate",
"--skip-offline",
"--start",
]
self.val_opts = [
"--after",
"--before",
"--booth-conf",
"--booth-key",
"--corosync_conf",
"--from",
"--group",
"--name",
"--node",
"--request-timeout",
"--to",
# "--wait", # --wait is a special case, it has its own tests
"-f",
"-p",
"-u",
]
# --debug is implicitly supported in all commands, tested separately
# in test_debug_implicit
self.bool_opts = sorted(MODIFIER_OPTIONS_BOOL - {"--debug"})
self.val_opts = sorted(MODIFIER_OPTIONS_VAL)

def _get_specified(self, *keys):
# pylint: disable=no-self-use
Expand Down
1 change: 1 addition & 0 deletions typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ relevatnt = "relevant"
resrource = "resource"
resourcs = "resources"
restarless = "restartless"
secretes = "secrets"
selimited = "delimited"
simualte = "simulate"
sotnith = "stonith"
Expand Down
Loading