mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cmd_runner: allow bool format to pass alternate (false) value (#5647)
* allow bool format to pass alternate (false) value * add changelog fragment
This commit is contained in:
parent
23aacc78e1
commit
be22ca0633
3 changed files with 13 additions and 2 deletions
2
changelogs/fragments/5647-cmd-runner-as-bool-false.yml
Normal file
2
changelogs/fragments/5647-cmd-runner-as-bool-false.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- cmd_runner module utils - ``cmd_runner_fmt.as_bool()`` can now take an extra parameter to format when value is false (https://github.com/ansible-collections/community.general/pull/5647).
|
|
@ -103,8 +103,13 @@ class _ArgFormat(object):
|
||||||
|
|
||||||
class _Format(object):
|
class _Format(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def as_bool(args):
|
def as_bool(args_true, args_false=None, ignore_none=None):
|
||||||
return _ArgFormat(lambda value: _ensure_list(args) if value else [])
|
if args_false is not None:
|
||||||
|
if ignore_none is None:
|
||||||
|
ignore_none = False
|
||||||
|
else:
|
||||||
|
args_false = []
|
||||||
|
return _ArgFormat(lambda value: _ensure_list(args_true) if value else _ensure_list(args_false), ignore_none=ignore_none)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def as_bool_not(args):
|
def as_bool_not(args):
|
||||||
|
|
|
@ -18,6 +18,10 @@ TC_FORMATS = dict(
|
||||||
simple_boolean__true=(fmt.as_bool, ("--superflag",), True, ["--superflag"]),
|
simple_boolean__true=(fmt.as_bool, ("--superflag",), True, ["--superflag"]),
|
||||||
simple_boolean__false=(fmt.as_bool, ("--superflag",), False, []),
|
simple_boolean__false=(fmt.as_bool, ("--superflag",), False, []),
|
||||||
simple_boolean__none=(fmt.as_bool, ("--superflag",), None, []),
|
simple_boolean__none=(fmt.as_bool, ("--superflag",), None, []),
|
||||||
|
simple_boolean_both__true=(fmt.as_bool, ("--superflag", "--falseflag"), True, ["--superflag"]),
|
||||||
|
simple_boolean_both__false=(fmt.as_bool, ("--superflag", "--falseflag"), False, ["--falseflag"]),
|
||||||
|
simple_boolean_both__none=(fmt.as_bool, ("--superflag", "--falseflag"), None, ["--falseflag"]),
|
||||||
|
simple_boolean_both__none_ig=(fmt.as_bool, ("--superflag", "--falseflag", True), None, []),
|
||||||
simple_boolean_not__true=(fmt.as_bool_not, ("--superflag",), True, []),
|
simple_boolean_not__true=(fmt.as_bool_not, ("--superflag",), True, []),
|
||||||
simple_boolean_not__false=(fmt.as_bool_not, ("--superflag",), False, ["--superflag"]),
|
simple_boolean_not__false=(fmt.as_bool_not, ("--superflag",), False, ["--superflag"]),
|
||||||
simple_boolean_not__none=(fmt.as_bool_not, ("--superflag",), None, ["--superflag"]),
|
simple_boolean_not__none=(fmt.as_bool_not, ("--superflag",), None, ["--superflag"]),
|
||||||
|
|
Loading…
Reference in a new issue