mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-08 04:57:16 +00:00
Cleanup.
This commit is contained in:
parent
64eb45f81b
commit
f4aeb65189
3 changed files with 13 additions and 10 deletions
|
|
@ -14,6 +14,9 @@ from ansible_collections.community.general.plugins.module_utils import cmd_runne
|
|||
if t.TYPE_CHECKING:
|
||||
from collections.abc import Callable, Mapping, Sequence
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.cmd_runner_fmt import ArgFormatType
|
||||
|
||||
ArgFormatter = t.Union[ArgFormatType, cmd_runner_fmt._ArgFormat]
|
||||
|
||||
|
||||
def _ensure_list(value):
|
||||
|
|
@ -84,7 +87,7 @@ class CmdRunner:
|
|||
self,
|
||||
module: AnsibleModule,
|
||||
command,
|
||||
arg_formats: Mapping[str, Callable[[t.Any], Sequence[t.Any]] | cmd_runner_fmt._ArgFormat] | None = None,
|
||||
arg_formats: Mapping[str, ArgFormatter] | None = None,
|
||||
default_args_order: str | Sequence[str] = (),
|
||||
check_rc: bool = False,
|
||||
force_lang: str = "C",
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ def _ensure_list(value: _T | Sequence[_T]) -> list[_T]:
|
|||
class _ArgFormat:
|
||||
def __init__(
|
||||
self,
|
||||
func: Callable[[t.Any], Sequence[t.Any]],
|
||||
func: ArgFormatType,
|
||||
ignore_none: bool | None = True,
|
||||
ignore_missing_value: bool = False,
|
||||
) -> None:
|
||||
|
|
@ -95,7 +95,7 @@ def as_fixed(*args: t.Any) -> _ArgFormat:
|
|||
return _ArgFormat(lambda value: _ensure_list(args), ignore_none=False, ignore_missing_value=True)
|
||||
|
||||
|
||||
def as_func(func: Callable[[t.Any], Sequence[t.Any]], ignore_none: bool | None = None) -> _ArgFormat:
|
||||
def as_func(func: ArgFormatType, ignore_none: bool | None = None) -> _ArgFormat:
|
||||
return _ArgFormat(func, ignore_none=ignore_none)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from ansible_collections.community.general.plugins.module_utils.module_helper im
|
|||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.cmd_runner_fmt import ArgFormatType
|
||||
from ansible_collections.community.general.plugins.module_utils.cmd_runner import ArgFormatter
|
||||
|
||||
|
||||
django_std_args = dict(
|
||||
|
|
@ -37,7 +37,7 @@ _pks = dict(
|
|||
primary_keys=dict(type="list", elements="str"),
|
||||
)
|
||||
|
||||
_django_std_arg_fmts: dict[str, ArgFormatType] = dict(
|
||||
_django_std_arg_fmts: dict[str, ArgFormatter] = dict(
|
||||
all=cmd_runner_fmt.as_bool("--all"),
|
||||
app=cmd_runner_fmt.as_opt_val("--app"),
|
||||
apps=cmd_runner_fmt.as_list(),
|
||||
|
|
@ -109,12 +109,12 @@ class _DjangoRunner(PythonRunner):
|
|||
class DjangoModuleHelper(ModuleHelper):
|
||||
module = {}
|
||||
django_admin_cmd: str | None = None
|
||||
arg_formats: dict[str, ArgFormatType] = {}
|
||||
arg_formats: dict[str, ArgFormatter] = {}
|
||||
django_admin_arg_order: tuple[str, ...] | str = ()
|
||||
_django_args: list[str] = []
|
||||
_check_mode_arg: str = ""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self.module["argument_spec"], self.arg_formats = self._build_args(
|
||||
self.module.get("argument_spec", {}), self.arg_formats, *(["std"] + self._django_args)
|
||||
)
|
||||
|
|
@ -123,9 +123,9 @@ class DjangoModuleHelper(ModuleHelper):
|
|||
self.vars.command = self.django_admin_cmd
|
||||
|
||||
@staticmethod
|
||||
def _build_args(arg_spec, arg_format, *names):
|
||||
res_arg_spec = {}
|
||||
res_arg_fmts = {}
|
||||
def _build_args(arg_spec, arg_format, *names) -> tuple[dict[str, t.Any], dict[str, ArgFormatter]]:
|
||||
res_arg_spec: dict[str, t.Any] = {}
|
||||
res_arg_fmts: dict[str, ArgFormatter] = {}
|
||||
for name in names:
|
||||
args, fmts = _args_menu[name]
|
||||
res_arg_spec = dict_merge(res_arg_spec, args)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue