Arg::required_if_eq
required_if_eq
Section titled “required_if_eq ”This argument is required only if the specified arg is present at runtime and its value equals val.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”name = "prog"[args]cfg = { long = "config", action = "set", required-if-eq = { arg = "other", value = "special" } }other = { long = "other", action = "set" }name: progargs: cfg: long: config action: set required-if-eq: arg: other value: special other: long: other action: set{ "name": "prog", "args": { "cfg": { "long": "config", "action": "set", "required-if-eq": { "arg": "other", "value": "special" } }, "other": { "long": "other", "action": "set" } }}prog --other not-specialOutput
Section titled “Output”claptrap_other='not-special'Example 2
Section titled “Example 2”name = "prog"[args]cfg = { long = "config", action = "set", required-if-eq = { arg = "other", value = "special" } }other = { long = "other", action = "set" }name: progargs: cfg: long: config action: set required-if-eq: arg: other value: special other: long: other action: set{ "name": "prog", "args": { "cfg": { "long": "config", "action": "set", "required-if-eq": { "arg": "other", "value": "special" } }, "other": { "long": "other", "action": "set" } }}prog --other specialOutput
Section titled “Output”error: the following required arguments were not provided: --config <cfg>
Usage: prog --other <other> --config <cfg>
For more information, try '--help'.Example 3
Section titled “Example 3”name = "prog"[args]cfg = { long = "config", action = "set", required-if-eq = { arg = "other", value = "special" } }other = { long = "other", action = "set", ignore-case = true }name: progargs: cfg: long: config action: set required-if-eq: arg: other value: special other: long: other action: set ignore-case: true{ "name": "prog", "args": { "cfg": { "long": "config", "action": "set", "required-if-eq": { "arg": "other", "value": "special" } }, "other": { "long": "other", "action": "set", "ignore-case": true } }}prog --other SPECIALOutput
Section titled “Output”error: the following required arguments were not provided: --config <cfg>
Usage: prog --other <other> --config <cfg>
For more information, try '--help'.Example 4
Section titled “Example 4”name = "prog"[args]cfg = { long = "config", action = "set", required-if-eq = { arg = "other", value = "special" } }other = { long = "other", action = "set" }name: progargs: cfg: long: config action: set required-if-eq: arg: other value: special other: long: other action: set{ "name": "prog", "args": { "cfg": { "long": "config", "action": "set", "required-if-eq": { "arg": "other", "value": "special" } }, "other": { "long": "other", "action": "set" } }}prog --other SPECIALOutput
Section titled “Output”claptrap_other='SPECIAL'