gui.model.form_options

gui.model.form_options(fields, values, strict=True)

Turn what the user typed into the options for cli_argv.

A value that equals the default of the parser is left out, so the command shown is as short as the one a person would type. A repeatable option is split like a shell line.

Parameters

Name Type Description Default
fields Sequence[FormField] The fields from form_fields. required
values Mapping[str, str | bool] The entries by FormField.key: a bool for a flag, else text. A missing key counts as empty. required
strict bool If True, a wrong or missing entry raises FormError. If False it is left out (a missing required option appears as its name in capitals), which is what the preview of the command needs while the user is still typing. True

Returns

Name Type Description
dict[str, object] dict[str, object]: The options by FormField.key.

Raises

Name Type Description
FormError In strict mode, if a required option is empty, a number does not parse or a choice is not one of the allowed values.

Examples

from spotregen.gui.model import cli_argv, display_command, form_fields, form_options

fields = form_fields("mutate")
options = form_options(fields, {"max": "5", "timeout": "120"})
print(options)
print(display_command(cli_argv("/r", "mutate", ["core.calc"], options)))
{'max': 5}
spotregen --root /r mutate core.calc --max 5