usecli 0.2.2__py3-none-any.whl → 0.2.4__py3-none-any.whl

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.
@@ -283,6 +283,33 @@ def _get_group_subcommands(
283
283
  return subcommands
284
284
 
285
285
 
286
+ def _prompt_for_text(prompt_text: str, empty_message: str) -> str:
287
+ """Read a non-empty value through rich's prompt-toolkit input seam.
288
+
289
+ ``console.input`` is patched by
290
+ :func:`usecli.cli.utils.interactive.prompt_input.install_prompt_input`, so
291
+ cursor keys, editing and history work instead of reaching a raw
292
+ ``input()``.
293
+ """
294
+ value = ""
295
+ while not value:
296
+ try:
297
+ value = console.input(
298
+ f"[bold {COLOR.SECONDARY}]{prompt_text}[/bold {COLOR.SECONDARY}]\n"
299
+ f"[bold {COLOR.SECONDARY}]└─> [/bold {COLOR.SECONDARY}]"
300
+ ).strip()
301
+ except EOFError:
302
+ value = ""
303
+ except KeyboardInterrupt:
304
+ ErrorHandler.display_warning("Cancelled by user")
305
+ raise typer.Exit(code=0)
306
+
307
+ if not value:
308
+ console.print(f"[{COLOR.ERROR}]{empty_message}[/{COLOR.ERROR}]")
309
+
310
+ return value
311
+
312
+
286
313
  def run_interactive(
287
314
  app: typer.Typer,
288
315
  cmd_parts: list[str] | None = None,
@@ -457,28 +484,13 @@ def run_interactive(
457
484
  )
458
485
  value = str(int_value)
459
486
  else:
460
- value = ""
461
- while not value:
462
- prompt_text = f"Enter value for '{arg_name}'"
463
- if arg_help:
464
- prompt_text += f" ({arg_help})"
465
- prompt_text += ":"
466
- console.print(f"[bold {COLOR.SECONDARY}]{prompt_text}")
467
- console.print(f"[bold {COLOR.SECONDARY}]└─> ", end="")
468
-
469
- try:
470
- user_input = input()
471
- value = user_input.strip()
472
- except EOFError:
473
- value = ""
474
- except KeyboardInterrupt:
475
- ErrorHandler.display_warning("Cancelled by user")
476
- raise typer.Exit(code=0)
477
-
478
- if not value:
479
- console.print(
480
- f"[{COLOR.ERROR}]Value is required. Please enter a value.[/{COLOR.ERROR}]"
481
- )
487
+ prompt_text = f"Enter value for '{arg_name}'"
488
+ if arg_help:
489
+ prompt_text += f" ({arg_help})"
490
+ prompt_text += ":"
491
+ value = _prompt_for_text(
492
+ prompt_text, "Value is required. Please enter a value."
493
+ )
482
494
 
483
495
  if " " in value:
484
496
  value = f'"{value}"'
@@ -555,23 +567,14 @@ def run_interactive(
555
567
  )
556
568
  option_values.append(f"{first_flag} {int_value}")
557
569
  else:
558
- opt_value = ""
559
- while not opt_value:
560
- prompt_text = f"[bold {COLOR.SECONDARY}]Value for {first_flag}"
561
- if help_text:
562
- prompt_text += f" ({help_text})"
563
- prompt_text += ":"
564
- console.print(prompt_text)
565
- console.print(f"[bold {COLOR.SECONDARY}]└─> ", end="")
566
- try:
567
- opt_value = input().strip()
568
- except KeyboardInterrupt:
569
- ErrorHandler.display_warning("Cancelled by user")
570
- raise typer.Exit(code=0)
571
- if not opt_value:
572
- console.print(
573
- f"[{COLOR.ERROR}]Value is required. Please enter a value or press Ctrl+C to cancel.[/{COLOR.ERROR}]"
574
- )
570
+ prompt_text = f"Value for {first_flag}"
571
+ if help_text:
572
+ prompt_text += f" ({help_text})"
573
+ prompt_text += ":"
574
+ opt_value = _prompt_for_text(
575
+ prompt_text,
576
+ "Value is required. Please enter a value or press Ctrl+C to cancel.",
577
+ )
575
578
  if " " in opt_value:
576
579
  opt_value = f'"{opt_value}"'
577
580
  option_values.append(f"{first_flag} {opt_value}")
@@ -3,10 +3,15 @@
3
3
  Typer >= 0.28 replaced ``TyperOption``'s ``type`` argument with a required
4
4
  ``type_descriptor``. usecli builds options directly to inject framework-wide
5
5
  flags, so it must support both layouts.
6
+
7
+ Typer also vendors its own click, whose parameter classes predate click's
8
+ ``get_error_hint(ctx)`` signature. usecli formats typer parameters with
9
+ click's exception classes, so the hint methods are adapted below.
6
10
  """
7
11
 
8
12
  from __future__ import annotations
9
13
 
14
+ import functools
10
15
  import inspect
11
16
  from typing import Any
12
17
 
@@ -17,6 +22,22 @@ _HAS_TYPE_DESCRIPTOR = (
17
22
  )
18
23
 
19
24
 
25
+ def _accept_click_ctx(method: Any) -> Any:
26
+ """Let click pass its context to a typer parameter's error hint method."""
27
+ if "ctx" in inspect.signature(method).parameters:
28
+ return method
29
+
30
+ @functools.wraps(method)
31
+ def get_error_hint(self: Any, ctx: Any = None) -> str:
32
+ return method(self)
33
+
34
+ return get_error_hint
35
+
36
+
37
+ TyperArgument.get_error_hint = _accept_click_ctx(TyperArgument.get_error_hint)
38
+ TyperOption.get_error_hint = _accept_click_ctx(TyperOption.get_error_hint)
39
+
40
+
20
41
  def _type_descriptor(annotation: type, *, argument: bool = False) -> Any:
21
42
  from typer._coercion import resolve_type_descriptor
22
43
  from typer.models import ArgumentInfo, OptionInfo
@@ -77,6 +77,20 @@ def get_framework_description() -> str | None:
77
77
  return summary or None
78
78
 
79
79
 
80
+ def _strip_blank_edges(text: str) -> str:
81
+ """Drop whitespace-only lines above and below rendered art.
82
+
83
+ Banner spacing belongs to ``banner.top_space``/``banner.bottom_space``;
84
+ literal blank lines baked into art would double it.
85
+ """
86
+ lines = text.split("\n")
87
+ while lines and not lines[0].strip():
88
+ lines.pop(0)
89
+ while lines and not lines[-1].strip():
90
+ lines.pop()
91
+ return "\n".join(lines)
92
+
93
+
80
94
  def _get_script_command_name(start_dir: Path | None = None) -> str | None:
81
95
  if start_dir is None:
82
96
  start_dir = Path.cwd()
@@ -212,6 +226,23 @@ def get_project_version() -> str | None:
212
226
  return None
213
227
 
214
228
 
229
+ def _banner_config():
230
+ """Config that owns the banner layout.
231
+
232
+ The usecli binary renders the framework banner, so its layout (file, font,
233
+ spacing, show flags) comes from the installed framework config rather than
234
+ the downstream project being scaffolded. Downstream CLIs keep using the
235
+ discovered project config.
236
+ """
237
+ if _running_framework_distribution() is None:
238
+ return get_config()
239
+
240
+ from usecli.shared.config.globals import PACKAGE_ROOT
241
+ from usecli.shared.config.manager import ConfigManager
242
+
243
+ return ConfigManager(start_dir=PACKAGE_ROOT)
244
+
245
+
215
246
  def render_plain_title(
216
247
  title: str,
217
248
  description: str | None = None,
@@ -265,7 +296,7 @@ def print_title(title: str | None = None) -> None:
265
296
 
266
297
  █████▓▓▓▓▓▒▒▒▒▒░░░░░░░░░░░░░░▒▒▒▒▒▓▓▓▓▓█████
267
298
  """
268
- config = get_config()
299
+ config = _banner_config()
269
300
 
270
301
  top_space = config.get("banner.top_space", True)
271
302
  bottom_space = config.get("banner.bottom_space", True)
@@ -313,7 +344,7 @@ def print_title(title: str | None = None) -> None:
313
344
  pass
314
345
 
315
346
  if title is None or title.lower() == "usecli":
316
- console.print(f"[{COLOR.PRIMARY}]{default_title_text}")
347
+ console.print(f"[{COLOR.PRIMARY}]{_strip_blank_edges(default_title_text)}")
317
348
  if bottom_space:
318
349
  console.print()
319
350
  return
@@ -70,6 +70,10 @@ class CommandService:
70
70
  project_commands_dir.relative_to(package_commands_dir)
71
71
  return
72
72
  except ValueError:
73
+ if command_name == "usecli":
74
+ # The framework binary exposes the framework's commands only;
75
+ # project commands belong to the project's own CLI.
76
+ return
73
77
  self._load_from_dir(project_commands_dir)
74
78
 
75
79
  def _load_version(self) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: usecli
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: A powerful Python CLI framework for building beautiful, developer-friendly command-line tools.
5
5
  Author: Edward Boswell
6
6
  Author-email: Edward Boswell <thememium@gmail.com>
@@ -12,7 +12,7 @@ usecli/cli/commands/defaults/base/about_command.py,sha256=MpOClmVh8nt4GaNkMZVbxV
12
12
  usecli/cli/commands/defaults/base/help_command.py,sha256=fb_OjfZl6dIYyg4sf7gVGocWZBoXZuybmrIOI921JN8,616
13
13
  usecli/cli/commands/defaults/base/inspire_command.py,sha256=QnbzZz09jEVO85v3QbPXnljTtdYXIt3piwbPqk8svxs,4865
14
14
  usecli/cli/commands/defaults/base/internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- usecli/cli/commands/defaults/base/internal/interactive_command.py,sha256=opJPYoFx2CWwaflHveLiKBK2fdCppNPaSveViU-cBjw,20686
15
+ usecli/cli/commands/defaults/base/internal/interactive_command.py,sha256=5ddfTxhIdngvLpI19urj9atd2OqjaXxjpVdwW0juZhc,20380
16
16
  usecli/cli/commands/defaults/base/upgrade_command.py,sha256=CbwgYhe5eusQJIHDIucZFwwjY2tresnVIAz4HrQNkKs,11209
17
17
  usecli/cli/commands/defaults/core/__init__.py,sha256=fPJE7iZcGtzVs0pteFLOTA8XXHJfjOPDTgBaIFYJ4PQ,74
18
18
  usecli/cli/commands/defaults/core/utils.py,sha256=_Zh68Xv-NSJQn_7vkNphgkpYfQOLu0nRr1wLrmI2xEw,5313
@@ -24,7 +24,7 @@ usecli/cli/commands/init_command.py,sha256=2qP0hRfieDFzN1cq0YeasIZ2xIDsfVY1MSkLu
24
24
  usecli/cli/config/__init__.py,sha256=ZXGIirxl3WStRR3g9mK0PNpnTQ8tkPmYB5PKdBA5ujY,80
25
25
  usecli/cli/config/colors.py,sha256=VY8rDgt_M7v3eFt_rGY8l2xxIh--7bFSqEuUE8kbrtk,27958
26
26
  usecli/cli/core/__init__.py,sha256=ZtgOO_gQoeXK7ZgELcFaWGADWiF8FSJ4TGLXAi3cNyE,2034
27
- usecli/cli/core/_typer_compat.py,sha256=Ehgm3IT7ZX2OoCiKKRFcu1bx8C6r0PjFAs49A2-H414,2204
27
+ usecli/cli/core/_typer_compat.py,sha256=CVYD43loXlqCWcTqmp9pE2sQtvm7RaU1T9J0r9wnUmQ,2934
28
28
  usecli/cli/core/base_command.py,sha256=RPm9CMIrSUz5HmQZgXjUVs0M5FguCSjs_FEbu4ldk00,21475
29
29
  usecli/cli/core/error/__init__.py,sha256=Q7rS_LX2hpUfgY7WMUxG25eLm16dUFCMFQWst-PGXzw,283
30
30
  usecli/cli/core/error/handler.py,sha256=Zjupb_YKerRQ_m4D_c_WTOo7EnUFzoqySronV_03fxY,3721
@@ -37,7 +37,7 @@ usecli/cli/core/exceptions/validation.py,sha256=94kVisVfM60BbQXXPgbbij-Wk-JG2oSE
37
37
  usecli/cli/core/runtime.py,sha256=oYw3utJfP6l0Ge-lh7LemzlpFfwhcTqd8f0UMjDw-uY,2734
38
38
  usecli/cli/core/ui/__init__.py,sha256=DlDpV0TkDHFgzy8QSKq1BtBXMZ0rPb83Doa9YJtJk8o,1182
39
39
  usecli/cli/core/ui/list.py,sha256=Xbd-yrBL2pbbFVTKyuhcE0P79SNkrPd36rjY8gTvQj0,17716
40
- usecli/cli/core/ui/title.py,sha256=HsyAXAqgfJByBowlXvChoAAzHX0ulAkWkjXDDossUso,11106
40
+ usecli/cli/core/ui/title.py,sha256=X1R1F9nDILymQtBmagngw0EB2mNijit7Hn2gri8Tw24,12149
41
41
  usecli/cli/core/ui/title.txt,sha256=FczT0qLn__wPje2HgWlG2QK-n9IFkrXbYB9r3BG-cME,592
42
42
  usecli/cli/core/validators/__init__.py,sha256=vh_vuBI4jjbyW_HK5YISSOqIF7hL3D1FH7yVwIZiLHQ,724
43
43
  usecli/cli/core/validators/network.py,sha256=ArjtXz8iu4VY_V3_KkPAuvKptieIQYLF_IgZx1nTpCo,1941
@@ -45,7 +45,7 @@ usecli/cli/core/validators/numeric.py,sha256=RnWdhzvpo6CH8gAO9HH9vDO6GgTR_YIBXo1
45
45
  usecli/cli/core/validators/path.py,sha256=4_yPF6YCTA7dYcMMUdR98KtgdE0VIDYH96Xu0oPIRDs,1727
46
46
  usecli/cli/core/validators/string.py,sha256=S8s5vcI5C1VgTsEFeaDEXM98r6a1uJHUUIUWMAPvUL8,1355
47
47
  usecli/cli/services/__init__.py,sha256=UsU5DrOuj54zExzb1aNr8pwL2JAxxBnGCxP0WS2_gm0,67
48
- usecli/cli/services/command_service.py,sha256=WBgAKtQKEhwymz6DqFQ7DhobixZZJBEuHzvw6hAVV9w,6333
48
+ usecli/cli/services/command_service.py,sha256=HjABXGX75oeweHDbOzFs8fX1LxZxvACejP1Rfv200E0,6543
49
49
  usecli/cli/templates/command.py.j2,sha256=aLmPbZmt7IkoX_VryhudMghz9RWqCT_1YbMsujPrmx0,2918
50
50
  usecli/cli/templates/theme.toml.j2,sha256=PXns8o-D6tGSOs33mItFOOU1gIZByRLlFzH5MhHBeZs,582
51
51
  usecli/cli/templates/usecli.config.toml.j2,sha256=x1pnaq9OwuNXOgAyBke3jHAQRMy4u9yEFwUcMkpZzNo,1875
@@ -80,8 +80,8 @@ usecli/shared/upgrades/service.py,sha256=mbdOlltlhy5aIoXQg-Z8bRZOBKx-V_ZE2LeFCaw
80
80
  usecli/shared/upgrades/settings.py,sha256=Fs3QPHC6WCZiR8vHR-p-iBhzt9Gb1pde_oqLpX-EanE,4054
81
81
  usecli/ui.py,sha256=692vBCg8NB1fnl50qftdfifL2HFw5QsM0ZzY5Y8GH-A,2893
82
82
  usecli/usecli.config.toml,sha256=GtbIu__TbPyl4D0P8g71BZDcTPuhIraphGlpRaYtbkg,1371
83
- usecli-0.2.2.dist-info/licenses/LICENSE,sha256=__gKAkMUpLmsNxVlHtoB_EZRb3qtfLICULaZFQdeBOs,1071
84
- usecli-0.2.2.dist-info/WHEEL,sha256=G_-rrEibZr7OEM7zdH1dSO6s-VdjfnS5PA4CLAdI9Vw,80
85
- usecli-0.2.2.dist-info/entry_points.txt,sha256=g-WrjhqUPo8h-70iEg5MXsbI6Fh5lHo0MCPcyDAeKFQ,75
86
- usecli-0.2.2.dist-info/METADATA,sha256=TfwzMS1CONtxZM2T2LOmhAcLzvpt-OwYE5KQgx7r4lo,13334
87
- usecli-0.2.2.dist-info/RECORD,,
83
+ usecli-0.2.4.dist-info/licenses/LICENSE,sha256=__gKAkMUpLmsNxVlHtoB_EZRb3qtfLICULaZFQdeBOs,1071
84
+ usecli-0.2.4.dist-info/WHEEL,sha256=G_-rrEibZr7OEM7zdH1dSO6s-VdjfnS5PA4CLAdI9Vw,80
85
+ usecli-0.2.4.dist-info/entry_points.txt,sha256=g-WrjhqUPo8h-70iEg5MXsbI6Fh5lHo0MCPcyDAeKFQ,75
86
+ usecli-0.2.4.dist-info/METADATA,sha256=4oA3U2nrZP6_rVymtBt5YaA_YkogrN5xzhSIOEWsx3w,13334
87
+ usecli-0.2.4.dist-info/RECORD,,
File without changes