cli-interview-kit 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/CHANGELOG.md +15 -0
  2. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/PKG-INFO +1 -1
  3. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/pyproject.toml +8 -2
  4. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/_model.py +3 -5
  5. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/_prompts.py +14 -6
  6. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/_suggest.py +4 -22
  7. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/app.py +33 -15
  8. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/command.py +33 -19
  9. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/console.py +85 -41
  10. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/interaction.py +38 -12
  11. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/interview.py +149 -54
  12. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/validators.py +48 -3
  13. cli_interview_kit-0.1.1/tests/test_docstrings.py +199 -0
  14. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/.gitignore +0 -0
  15. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/LICENSE +0 -0
  16. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/README.md +0 -0
  17. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/docs/design.md +0 -0
  18. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/docs/requirements.md +0 -0
  19. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/examples/projects.py +0 -0
  20. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/__init__.py +0 -0
  21. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/_help.py +0 -0
  22. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/errors.py +0 -0
  23. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/src/cli_interview_kit/py.typed +0 -0
  24. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/conftest.py +0 -0
  25. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/helpers.py +0 -0
  26. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/snapshots/projects_new_questions.json +0 -0
  27. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_app.py +0 -0
  28. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_console.py +0 -0
  29. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_declarations.py +0 -0
  30. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_help.py +0 -0
  31. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_questions_document.py +0 -0
  32. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_readme.py +0 -0
  33. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_suggest.py +0 -0
  34. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_terminal.py +0 -0
  35. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_unattended.py +0 -0
  36. {cli_interview_kit-0.1.0 → cli_interview_kit-0.1.1}/tests/test_validators.py +0 -0
@@ -7,6 +7,21 @@ version).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.1] - 2026-11-27
11
+
12
+ No behavior changes.
13
+
14
+ ### Added
15
+
16
+ - A Code of Conduct.
17
+
18
+ ### Changed
19
+
20
+ - Docstrings follow the NumPy convention (parameters, returns, raises, attributes and methods,
21
+ without types) and are checked in CI.
22
+ - CI now lints for common security issues (ruff's `S`/bandit rules), matching the scrutiny a
23
+ package installed by third parties warrants.
24
+
10
25
  ## [0.1.0] - 2026-11-27
11
26
 
12
27
  First release.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cli-interview-kit
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Python CLIs whose prompts are declared once and answered at the terminal, by flags, or by an AI assistant.
5
5
  Project-URL: Homepage, https://github.com/Northbridge-Capital/cli-interview-kit
6
6
  Project-URL: Source, https://github.com/Northbridge-Capital/cli-interview-kit
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cli-interview-kit"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "Python CLIs whose prompts are declared once and answered at the terminal, by flags, or by an AI assistant."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -59,7 +59,13 @@ line-length = 100
59
59
  target-version = "py311"
60
60
 
61
61
  [tool.ruff.lint]
62
- select = ["E", "F", "W", "I", "B", "UP", "DTZ", "SIM", "PT", "RUF", "C4", "PIE"]
62
+ select = ["E", "F", "W", "I", "B", "UP", "DTZ", "S", "SIM", "PT", "RUF", "C4", "PIE", "D"]
63
+
64
+ [tool.ruff.lint.pydocstyle]
65
+ convention = "numpy"
66
+
67
+ [tool.ruff.lint.per-file-ignores]
68
+ "tests/**/*.py" = ["D", "S101", "S102"]
63
69
 
64
70
  [tool.ruff.format]
65
71
  line-ending = "lf"
@@ -6,10 +6,8 @@ from pydantic import BaseModel, ConfigDict
6
6
 
7
7
 
8
8
  class FrozenModel(BaseModel):
9
- """Immutable pydantic base for every declaration and value object.
10
-
11
- Declarations hold callables (run functions, validators, choice sources),
12
- so arbitrary types are allowed.
13
- """
9
+ """An immutable pydantic base for every declaration and value object."""
14
10
 
11
+ # Declarations hold callables (run functions, validators, choice sources), so arbitrary
12
+ # types are allowed.
15
13
  model_config = ConfigDict(frozen=True, arbitrary_types_allowed=True, extra="forbid")
@@ -12,10 +12,21 @@ from cli_interview_kit.validators import Validator, all_of, non_empty
12
12
  def parse_kv(items: Sequence[str] | None, flag: str) -> dict[str, str]:
13
13
  """Parse repeated ``KEY=VALUE`` flag values into a dict.
14
14
 
15
+ Parameters
16
+ ----------
17
+ items
18
+ The values of a repeatable flag, or ``None`` if it was not given.
19
+ flag
20
+ The flag's name, for error messages.
21
+
22
+ Returns
23
+ -------
24
+ The values, by key.
25
+
15
26
  Raises
16
27
  ------
17
28
  CliError
18
- If a value has no ``=`` or an empty key.
29
+ A value has no ``=`` or an empty key.
19
30
  """
20
31
  result: dict[str, str] = {}
21
32
  for item in items or ():
@@ -69,11 +80,8 @@ def prompt_pairs(
69
80
 
70
81
 
71
82
  def _keep_adding(console: Console, label: str, required: bool, collected: int) -> bool:
72
- """Return whether to ask for another item.
73
-
74
- A required collection asks for its first item straight away, so it can
75
- never end up empty.
76
- """
83
+ """Return whether to ask for another item."""
84
+ # A required collection asks for its first item straight away, so it can never end up empty.
77
85
  if collected:
78
86
  return console.confirm("Add another?", default=False)
79
87
  return required or console.confirm(f"Add {_with_article(label)}?", default=False)
@@ -47,6 +47,9 @@ class _State(BaseModel):
47
47
  return found[:MAX_SHOWN]
48
48
 
49
49
 
50
+ # ``validate`` returns ``True`` when valid, else the message to show. ``style`` uses the ``qmark``,
51
+ # ``question``, ``answer``, ``pointer``, ``suggestion`` and ``validation-toolbar`` classes, like
52
+ # the other prompts. The answer is ``None`` when the user cancels with Ctrl-C.
50
53
  def suggest_text(
51
54
  prompt: str,
52
55
  suggestions: Sequence[str],
@@ -55,28 +58,7 @@ def suggest_text(
55
58
  validate: Callable[[str], bool | str] | None = None,
56
59
  style: BaseStyle | None = None,
57
60
  ) -> str | None:
58
- """Ask for free text with suggestions listed under the input.
59
-
60
- Parameters
61
- ----------
62
- prompt : str
63
- The question.
64
- suggestions : Sequence[str]
65
- Values listed while they match what is typed.
66
- default : str, optional
67
- Initial input.
68
- validate : Callable[[str], bool | str] | None, optional
69
- ``True`` when valid, else the message to show.
70
- style : BaseStyle | None, optional
71
- Uses the ``qmark``, ``question``, ``answer``, ``pointer``,
72
- ``suggestion`` and ``validation-toolbar`` classes, like the other
73
- prompts.
74
-
75
- Returns
76
- -------
77
- str | None
78
- The answer, or ``None`` when cancelled with Ctrl-C.
79
- """
61
+ """Ask for free text with suggestions listed under the input."""
80
62
  state = _State(suggestions=list(dict.fromkeys(suggestions)))
81
63
  buffer = Buffer(document=Document(default, len(default)), multiline=False)
82
64
  buffer.on_text_changed += lambda _buffer: _reset(state) # pyright: ignore[reportUnknownLambdaType]
@@ -37,21 +37,23 @@ _PATH = "_cik_path"
37
37
 
38
38
 
39
39
  class _ArgumentParser(argparse.ArgumentParser):
40
- """An ``ArgumentParser`` whose help and usage render through rich.
40
+ """An ``ArgumentParser`` whose help and usage render through rich."""
41
41
 
42
- ``add_subparsers()`` gives every subparser its parent's class, so this
43
- one subclass covers every command.
44
- """
42
+ # ``add_subparsers()`` gives every subparser its parent's class, so this one subclass covers
43
+ # every command.
45
44
 
46
45
  def print_help(self, file: object = None) -> None:
46
+ """Print the help through rich, ignoring ``file``."""
47
47
  _ = file
48
48
  print_help(self)
49
49
 
50
50
  def print_usage(self, file: object = None) -> None:
51
+ """Print the usage line through rich, ignoring ``file``."""
51
52
  _ = file
52
53
  print_usage(self)
53
54
 
54
55
  def error(self, message: str) -> NoReturn:
56
+ """Print the usage and the message, then exit with status 2."""
55
57
  print_usage(self)
56
58
  Console().error(message)
57
59
  self.exit(2)
@@ -62,17 +64,24 @@ class App(FrozenModel):
62
64
 
63
65
  Attributes
64
66
  ----------
65
- name : str
67
+ name
66
68
  Program name.
67
- description : str
69
+ description
68
70
  Top-level help.
69
- version : str
71
+ version
70
72
  What ``--version`` prints after the name.
71
- commands : tuple[Command, ...]
73
+ commands
72
74
  The top-level commands.
73
- expected_errors : tuple[type[Exception], ...]
75
+ expected_errors
74
76
  Further exception types whose message is reported like a
75
77
  ``CliError``, for failures the app's own libraries raise.
78
+
79
+ Methods
80
+ -------
81
+ main
82
+ Run the command ``argv`` selects and return the exit code.
83
+ build_parser
84
+ Return the argument parser for every declared command.
76
85
  """
77
86
 
78
87
  name: str = Field(min_length=1)
@@ -94,14 +103,17 @@ class App(FrozenModel):
94
103
 
95
104
  Parameters
96
105
  ----------
97
- argv : Sequence[str] | None, optional
106
+ argv
98
107
  The arguments after the program name; ``sys.argv[1:]`` if omitted.
99
108
 
100
109
  Returns
101
110
  -------
102
- int
103
- 0 on success, 1 on a failure, 130 when interrupted. A usage
104
- error exits 2 through ``SystemExit``, as argparse does.
111
+ The exit code: 0 on success, 1 on a failure, 130 when interrupted.
112
+
113
+ Raises
114
+ ------
115
+ SystemExit
116
+ A usage error (an unknown flag, a bad choice) exits with status 2, as argparse does.
105
117
  """
106
118
  console = Console()
107
119
  args = self.build_parser().parse_args(argv)
@@ -127,7 +139,12 @@ class App(FrozenModel):
127
139
  return 0
128
140
 
129
141
  def build_parser(self) -> argparse.ArgumentParser:
130
- """Return the argument parser for every declared command."""
142
+ """Return the argument parser for every declared command.
143
+
144
+ Returns
145
+ -------
146
+ The parser, with ``--version``, ``--debug`` and one subparser per command.
147
+ """
131
148
  parser = _ArgumentParser(prog=self.name, description=self.description)
132
149
  _ = parser.add_argument(
133
150
  "--version", action="version", version=f"{self.name} {self.version}"
@@ -141,6 +158,7 @@ class App(FrozenModel):
141
158
  return parser
142
159
 
143
160
  def _dispatch(self, console: Console, values: dict[str, Any]) -> None:
161
+ """Print the selected command's ``--questions``, or answer its interview and run it."""
144
162
  command: Command = values[_COMMAND]
145
163
  command_line = " ".join(values[_PATH])
146
164
  options = {option.dest: values.get(option.dest) for option in command.options}
@@ -155,7 +173,7 @@ class App(FrozenModel):
155
173
  )
156
174
  answers = command.interview.run(console, interaction, values, options)
157
175
  # A command without a run has subcommands, and argparse requires one.
158
- assert command.run is not None
176
+ assert command.run is not None # noqa: S101 -- see the comment above
159
177
  command.run(
160
178
  Invocation(console=console, interaction=interaction, answers=answers, options=options)
161
179
  )
@@ -38,24 +38,31 @@ class Option(FrozenModel):
38
38
 
39
39
  Attributes
40
40
  ----------
41
- dest : str
41
+ dest
42
42
  The name the value is read by, in snake_case; the flag is ``--``
43
43
  plus the name with dashes.
44
- help : str
44
+ help
45
45
  Help text.
46
- kind : Literal["switch", "value", "append", "positional"]
46
+ kind
47
47
  ``switch`` is an on/off flag; ``value`` takes one value; ``append``
48
48
  is repeatable; ``positional`` is an argument.
49
- metavar : str | None
49
+ metavar
50
50
  Value placeholder in help.
51
- choices : tuple[str, ...]
51
+ choices
52
52
  Allowed values.
53
- nargs : str | None
53
+ nargs
54
54
  A positional's arity, e.g. ``"*"``.
55
- convert : Callable[[str], Any] | None
55
+ convert
56
56
  Converts and checks a value; raising ``ValueError`` is a usage error.
57
- exclusive : str | None
57
+ exclusive
58
58
  Options sharing this name are mutually exclusive.
59
+ flag
60
+ The option's flag, or its name for a positional.
61
+
62
+ Methods
63
+ -------
64
+ describe
65
+ Describe the option as ``--questions`` lists it.
59
66
  """
60
67
 
61
68
  dest: str = Field(pattern=r"^[a-z][a-z0-9_]*$")
@@ -86,7 +93,12 @@ class Option(FrozenModel):
86
93
  return "--" + self.dest.replace("_", "-")
87
94
 
88
95
  def describe(self) -> dict[str, Any]:
89
- """Return the option as ``--questions`` lists it."""
96
+ """Describe the option as ``--questions`` lists it.
97
+
98
+ Returns
99
+ -------
100
+ The option's flag, kind and help.
101
+ """
90
102
  return {"flag": self.flag, "kind": self.kind, "help": self.help}
91
103
 
92
104
 
@@ -95,14 +107,14 @@ class Invocation(FrozenModel):
95
107
 
96
108
  Attributes
97
109
  ----------
98
- console : Console
110
+ console
99
111
  Output and prompts.
100
- interaction : Interaction
112
+ interaction
101
113
  Whether the run may prompt and has consent; pass it to
102
114
  ``Consent.ask``.
103
- answers : dict[str, Any]
115
+ answers
104
116
  The answers of the questions that applied, by key.
105
- options : dict[str, Any]
117
+ options
106
118
  The options' values, by ``dest``.
107
119
  """
108
120
 
@@ -117,19 +129,21 @@ class Command(FrozenModel):
117
129
 
118
130
  Attributes
119
131
  ----------
120
- name : str
132
+ name
121
133
  The command's name on the command line.
122
- help : str
134
+ help
123
135
  One-line help.
124
- options : tuple[Option, ...]
136
+ options
125
137
  Plain options and positionals.
126
- interview : Interview
138
+ interview
127
139
  Questions and consents. A command with any gets ``--yes`` and
128
140
  ``--questions``.
129
- run : Callable[[Invocation], None] | None
141
+ run
130
142
  What the command does; ``None`` for a group of subcommands.
131
- subcommands : tuple[Command, ...]
143
+ subcommands
132
144
  Nested commands.
145
+ interactive
146
+ Whether the command has questions or consents.
133
147
  """
134
148
 
135
149
  name: str = Field(pattern=r"^[a-z][a-z0-9-]*$")
@@ -51,19 +51,25 @@ class Console:
51
51
 
52
52
  Methods
53
53
  -------
54
- print(renderable)
55
- Print a result to stdout: text, rich markup or any rich renderable.
56
- info(message), success(message), warning(message), error(message)
57
- Print a labelled status line to stderr, as plain text.
58
- progress(description)
54
+ print
55
+ Print a result to stdout: text, rich markup or a rich renderable.
56
+ info
57
+ Print an informational status line.
58
+ success
59
+ Print a success status line.
60
+ warning
61
+ Print a warning status line.
62
+ error
63
+ Print an error status line.
64
+ progress
59
65
  Show a progress bar on stderr for a series of named steps.
60
- select(prompt, choices, label)
66
+ select
61
67
  Ask for one of ``choices``.
62
- checkbox(prompt, choices, label, checked)
68
+ checkbox
63
69
  Ask for any number of ``choices``.
64
- confirm(prompt, default)
70
+ confirm
65
71
  Ask a yes/no question.
66
- text(prompt, default, validate, suggestions)
72
+ text
67
73
  Ask for free text, validated, optionally with suggestions.
68
74
  """
69
75
 
@@ -72,26 +78,57 @@ class Console:
72
78
  self._err = RichConsole(stderr=True)
73
79
 
74
80
  def print(self, renderable: object) -> None:
75
- """Print a result to stdout: text, rich markup or a rich renderable."""
81
+ """Print a result to stdout: text, rich markup or a rich renderable.
82
+
83
+ Parameters
84
+ ----------
85
+ renderable
86
+ Text, rich markup or any rich renderable.
87
+ """
76
88
  self._out.print(renderable)
77
89
 
78
90
  def info(self, message: str) -> None:
79
- """Print an informational status line."""
91
+ """Print an informational status line.
92
+
93
+ Parameters
94
+ ----------
95
+ message
96
+ The text to show, printed literally.
97
+ """
80
98
  self._status("INFO", "bold cyan", message)
81
99
 
82
100
  def success(self, message: str) -> None:
83
- """Print a success status line."""
101
+ """Print a success status line.
102
+
103
+ Parameters
104
+ ----------
105
+ message
106
+ The text to show, printed literally.
107
+ """
84
108
  self._status("OK", "bold green", message)
85
109
 
86
110
  def warning(self, message: str) -> None:
87
- """Print a warning status line."""
111
+ """Print a warning status line.
112
+
113
+ Parameters
114
+ ----------
115
+ message
116
+ The text to show, printed literally.
117
+ """
88
118
  self._status("WARN", "bold yellow", message)
89
119
 
90
120
  def error(self, message: str) -> None:
91
- """Print an error status line."""
121
+ """Print an error status line.
122
+
123
+ Parameters
124
+ ----------
125
+ message
126
+ The text to show, printed literally.
127
+ """
92
128
  self._status("ERROR", "bold red", message)
93
129
 
94
130
  def _status(self, label: str, style: str, message: str) -> None:
131
+ """Print a labelled status line to stderr."""
95
132
  # Soft wrap: a long message stays one line when piped, for whatever reads it.
96
133
  self._err.print(
97
134
  Text.assemble((label, style), " ", message), highlight=False, soft_wrap=True
@@ -103,14 +140,13 @@ class Console:
103
140
 
104
141
  Parameters
105
142
  ----------
106
- description : str
143
+ description
107
144
  What the steps do together, e.g. ``"Checking files"``.
108
145
 
109
146
  Yields
110
147
  ------
111
- Callable[[int, int, str], None]
112
- ``update(index, total, detail)``: call it before each step, with
113
- the step's 1-based index and what it is doing.
148
+ ``update(index, total, detail)``: call it before each step, with the step's
149
+ 1-based index and what it is doing.
114
150
  """
115
151
  with Progress(
116
152
  TextColumn("[bold cyan]INFO[/bold cyan]"),
@@ -132,24 +168,23 @@ class Console:
132
168
 
133
169
  Parameters
134
170
  ----------
135
- prompt : str
171
+ prompt
136
172
  The question.
137
- choices : Sequence[T]
173
+ choices
138
174
  What can be chosen.
139
- label : Callable[[T], str]
175
+ label
140
176
  How each choice is shown.
141
177
 
142
178
  Returns
143
179
  -------
144
- T
145
- The chosen item.
180
+ The chosen item.
146
181
 
147
182
  Raises
148
183
  ------
149
184
  CliError
150
- If there is nothing to choose from.
185
+ There is nothing to choose from.
151
186
  KeyboardInterrupt
152
- If the user cancels.
187
+ The user cancels.
153
188
  """
154
189
  if not choices:
155
190
  raise CliError(f"{prompt}: nothing to choose from.")
@@ -173,27 +208,26 @@ class Console:
173
208
 
174
209
  Parameters
175
210
  ----------
176
- prompt : str
211
+ prompt
177
212
  The question.
178
- choices : Sequence[T]
213
+ choices
179
214
  What can be chosen.
180
- label : Callable[[T], str]
215
+ label
181
216
  How each choice is shown.
182
- checked : Sequence[T] | None, optional
217
+ checked
183
218
  The choices ticked when the prompt opens; every choice when
184
219
  omitted, so the common answer "all of them" is one keypress.
185
220
 
186
221
  Returns
187
222
  -------
188
- list[T]
189
- The chosen items, in ``choices`` order.
223
+ The chosen items, in ``choices`` order.
190
224
 
191
225
  Raises
192
226
  ------
193
227
  CliError
194
- If there is nothing to choose from.
228
+ There is nothing to choose from.
195
229
  KeyboardInterrupt
196
- If the user cancels.
230
+ The user cancels.
197
231
  """
198
232
  if not choices:
199
233
  raise CliError(f"{prompt}: nothing to choose from.")
@@ -214,10 +248,21 @@ class Console:
214
248
  def confirm(self, prompt: str, default: bool) -> bool:
215
249
  """Ask a yes/no question.
216
250
 
251
+ Parameters
252
+ ----------
253
+ prompt
254
+ The question.
255
+ default
256
+ The answer an empty reply gives.
257
+
258
+ Returns
259
+ -------
260
+ The answer.
261
+
217
262
  Raises
218
263
  ------
219
264
  KeyboardInterrupt
220
- If the user cancels.
265
+ The user cancels.
221
266
  """
222
267
  answer: object = questionary.confirm(prompt, default=default, style=PROMPT_STYLE).ask()
223
268
  if not isinstance(answer, bool):
@@ -235,26 +280,25 @@ class Console:
235
280
 
236
281
  Parameters
237
282
  ----------
238
- prompt : str
283
+ prompt
239
284
  The question.
240
- default : str, optional
285
+ default
241
286
  Text the input starts with.
242
- validate : Validator | None, optional
287
+ validate
243
288
  Raises ``ValueError`` for an invalid answer; its message is shown
244
289
  under the input until the answer changes.
245
- suggestions : Sequence[str], optional
290
+ suggestions
246
291
  Values listed under the input while they match what is typed.
247
292
  Any other value can still be entered.
248
293
 
249
294
  Returns
250
295
  -------
251
- str
252
- The answer.
296
+ The answer.
253
297
 
254
298
  Raises
255
299
  ------
256
300
  KeyboardInterrupt
257
- If the user cancels.
301
+ The user cancels.
258
302
  """
259
303
 
260
304
  def _verdict(value: str) -> bool | str:
@@ -28,13 +28,18 @@ class Interaction(FrozenModel):
28
28
 
29
29
  Attributes
30
30
  ----------
31
- can_prompt : bool
31
+ can_prompt
32
32
  Stdin is a terminal and ``--yes`` was not given.
33
- consent : bool
33
+ consent
34
34
  ``--yes`` was given: every declared consent is granted.
35
- declared : frozenset[str]
35
+ declared
36
36
  The keys of the consents the running command declares; only these
37
37
  can be asked for.
38
+
39
+ Methods
40
+ -------
41
+ resolve
42
+ Return the interaction for a run, from ``--yes`` and the terminal.
38
43
  """
39
44
 
40
45
  can_prompt: bool
@@ -43,7 +48,19 @@ class Interaction(FrozenModel):
43
48
 
44
49
  @classmethod
45
50
  def resolve(cls, yes: bool, declared: frozenset[str] = frozenset()) -> Interaction:
46
- """Return the interaction for a run, from ``--yes`` and the terminal."""
51
+ """Return the interaction for a run, from ``--yes`` and the terminal.
52
+
53
+ Parameters
54
+ ----------
55
+ yes
56
+ Whether ``--yes`` was given.
57
+ declared
58
+ The keys of the consents the running command declares.
59
+
60
+ Returns
61
+ -------
62
+ The interaction every question and consent of the run follows.
63
+ """
47
64
  return cls(can_prompt=sys.stdin.isatty() and not yes, consent=yes, declared=declared)
48
65
 
49
66
 
@@ -56,14 +73,19 @@ class Consent(FrozenModel):
56
73
 
57
74
  Attributes
58
75
  ----------
59
- key : str
76
+ key
60
77
  Stable identifier.
61
- when : str
78
+ when
62
79
  When the command asks for it and what it allows, for ``--questions``.
63
- safe_default : bool | None
80
+ safe_default
64
81
  The answer when nobody can be asked and ``--yes`` was not given, and
65
82
  the prompt's default. ``None`` means only ``--yes`` or a person can
66
83
  give it.
84
+
85
+ Methods
86
+ -------
87
+ ask
88
+ Return whether the run has this consent.
67
89
  """
68
90
 
69
91
  key: str = Field(min_length=1)
@@ -75,19 +97,23 @@ class Consent(FrozenModel):
75
97
 
76
98
  Parameters
77
99
  ----------
78
- console : Console
100
+ console
79
101
  Where to ask.
80
- interaction : Interaction
102
+ interaction
81
103
  The run's interaction.
82
- message : str
104
+ message
83
105
  The question to ask, saying exactly what will happen.
84
106
 
107
+ Returns
108
+ -------
109
+ Whether the run has this consent.
110
+
85
111
  Raises
86
112
  ------
87
113
  DeclarationError
88
- If the running command does not declare this consent.
114
+ The running command does not declare this consent.
89
115
  CliError
90
- If nobody can be asked, ``--yes`` was not given, and the consent
116
+ Nobody can be asked, ``--yes`` was not given, and the consent
91
117
  has no safe default.
92
118
  """
93
119
  if self.key not in interaction.declared: