usecli 0.1.82__tar.gz → 0.2.0__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.
- {usecli-0.1.82 → usecli-0.2.0}/PKG-INFO +23 -5
- {usecli-0.1.82 → usecli-0.2.0}/README.md +20 -2
- {usecli-0.1.82 → usecli-0.2.0}/pyproject.toml +4 -7
- {usecli-0.1.82 → usecli-0.2.0}/pyproject.toml.orig +4 -7
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/__init__.py +1 -1
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/bundler/__init__.py +4 -4
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/base/inspire_command.py +0 -5
- usecli-0.1.82/src/usecli/cli/commands/defaults/base/internal/fzf_command.py → usecli-0.2.0/src/usecli/cli/commands/defaults/base/internal/interactive_command.py +141 -102
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/init_command.py +159 -19
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/config/colors.py +52 -20
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/base_command.py +27 -3
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/error/handler.py +1 -1
- usecli-0.2.0/src/usecli/cli/core/ui/title.py +257 -0
- usecli-0.2.0/src/usecli/cli/templates/usecli.config.toml.j2 +46 -0
- usecli-0.2.0/src/usecli/cli/utils/interactive/terminal_menu.py +516 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/entry.py +2 -3
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/config/manager.py +139 -83
- usecli-0.2.0/src/usecli/usecli.config.toml +21 -0
- usecli-0.1.82/src/usecli/cli/core/ui/title.py +0 -148
- usecli-0.1.82/src/usecli/cli/templates/usecli.config.toml.j2 +0 -21
- usecli-0.1.82/src/usecli/cli/utils/interactive/terminal_menu.py +0 -210
- usecli-0.1.82/src/usecli/usecli.config.toml +0 -14
- {usecli-0.1.82 → usecli-0.2.0}/LICENSE +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/bundler/__main__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/README.md +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/custom/README.md +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/custom/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/base/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/base/about_command.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/base/help_command.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/base/internal/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/base/upgrade_command.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/core/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/core/utils.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/make/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/make/make_bundle_command.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/make/make_command.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/commands/defaults/make/make_theme_command.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/config/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/_typer_compat.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/error/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/error/utils.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/exceptions/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/exceptions/base.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/exceptions/config.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/exceptions/usage.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/exceptions/validation.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/runtime.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/ui/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/ui/list.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/ui/title.txt +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/validators/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/validators/network.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/validators/numeric.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/validators/path.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/core/validators/string.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/services/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/services/command_service.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/templates/command.py.j2 +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/templates/theme.toml.j2 +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/ayu_dark.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/catppuccin_frappe.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/catppuccin_latte.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/catppuccin_macchiato.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/catppuccin_mocha.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/default.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/dracula.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/gruvbox_dark.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/nord.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/themes/tokyo_night.toml +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/utils/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/cli/utils/interactive/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/menu.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/params.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/progress.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/config/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/config/globals.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/upgrades/__init__.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/upgrades/checker.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/upgrades/discovery.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/upgrades/installer.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/upgrades/pyproject.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/upgrades/service.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/shared/upgrades/settings.py +0 -0
- {usecli-0.1.82 → usecli-0.2.0}/src/usecli/ui.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: usecli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
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>
|
|
@@ -11,13 +11,12 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
12
|
Requires-Dist: case-converter>=1.2.0
|
|
13
13
|
Requires-Dist: click>=8.4.2
|
|
14
|
-
Requires-Dist: fzf-bin>=0.74.1
|
|
15
14
|
Requires-Dist: jinja2>=3.1.6
|
|
16
|
-
Requires-Dist: pyfiglet>=1.0.4
|
|
17
15
|
Requires-Dist: rich>=15.0.0
|
|
18
16
|
Requires-Dist: simple-term-menu>=1.6.6
|
|
19
17
|
Requires-Dist: tomli>=2.4.1
|
|
20
18
|
Requires-Dist: typer>=0.27.0
|
|
19
|
+
Requires-Dist: pyfiglet>=1.0.4 ; extra == 'figlet'
|
|
21
20
|
Requires-Dist: pyinstaller>=6.21.0 ; extra == 'pyinstaller'
|
|
22
21
|
Requires-Python: >=3.10
|
|
23
22
|
Project-URL: Homepage, https://github.com/thememium/usecli
|
|
@@ -25,6 +24,7 @@ Project-URL: Documentation, https://github.com/thememium/usecli
|
|
|
25
24
|
Project-URL: Repository, https://github.com/thememium/usecli.git
|
|
26
25
|
Project-URL: Issues, https://github.com/thememium/usecli/issues
|
|
27
26
|
Project-URL: Changelog, https://github.com/thememium/usecli/blob/master/CHANGELOG.md
|
|
27
|
+
Provides-Extra: figlet
|
|
28
28
|
Provides-Extra: pyinstaller
|
|
29
29
|
Description-Content-Type: text/markdown
|
|
30
30
|
|
|
@@ -68,7 +68,7 @@ Description-Content-Type: text/markdown
|
|
|
68
68
|
useCli A powerful Python CLI framework for building beautiful, developer-friendly command-line tools. It gives you:
|
|
69
69
|
|
|
70
70
|
- **Prefix matching** — Type `he` instead of `help`
|
|
71
|
-
- **Interactive mode** —
|
|
71
|
+
- **Interactive mode** — Searchable command picker
|
|
72
72
|
- **Auto-generated help** — Clean, styled output
|
|
73
73
|
- **Command scaffolding** — `make:command` generates boilerplate
|
|
74
74
|
- **UI components** — Prompts, menus, styled console output
|
|
@@ -97,6 +97,18 @@ pip install usecli
|
|
|
97
97
|
usecli init
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
### ASCII-art titles (optional)
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
uv add "usecli[figlet]"
|
|
104
|
+
# or: pip install "usecli[figlet]"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The extra installs [pyfiglet](https://github.com/pwaller/pyfiglet). With it,
|
|
108
|
+
`usecli init` offers a figlet font picker and banners are rendered in the
|
|
109
|
+
chosen font. Without it, the picker is skipped and banners print as colored
|
|
110
|
+
text: title and version on one line, description below.
|
|
111
|
+
|
|
100
112
|
### Create a command
|
|
101
113
|
|
|
102
114
|
```sh
|
|
@@ -141,10 +153,16 @@ usecli ma:co # make:command
|
|
|
141
153
|
### Interactive Mode
|
|
142
154
|
|
|
143
155
|
```sh
|
|
144
|
-
usecli --interactive #
|
|
156
|
+
usecli --interactive # Searchable picker for all commands
|
|
145
157
|
usecli -i hello # Run 'hello' command interactively
|
|
146
158
|
```
|
|
147
159
|
|
|
160
|
+
The picker opens in-place with vim-style keys: `j`/`k` or the arrow keys move,
|
|
161
|
+
`/` starts search, and enter runs the highlighted command. `esc` leaves search
|
|
162
|
+
mode but keeps the filter active (normal-mode navigation still works); `ctrl-u`
|
|
163
|
+
clears the filter. Command names, descriptions, the title and the status bar use
|
|
164
|
+
your theme colors; the highlighted row switches to the theme's highlight style.
|
|
165
|
+
|
|
148
166
|
### Command Groups
|
|
149
167
|
|
|
150
168
|
Colon-separated commands group automatically in help:
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
useCli A powerful Python CLI framework for building beautiful, developer-friendly command-line tools. It gives you:
|
|
39
39
|
|
|
40
40
|
- **Prefix matching** — Type `he` instead of `help`
|
|
41
|
-
- **Interactive mode** —
|
|
41
|
+
- **Interactive mode** — Searchable command picker
|
|
42
42
|
- **Auto-generated help** — Clean, styled output
|
|
43
43
|
- **Command scaffolding** — `make:command` generates boilerplate
|
|
44
44
|
- **UI components** — Prompts, menus, styled console output
|
|
@@ -67,6 +67,18 @@ pip install usecli
|
|
|
67
67
|
usecli init
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
### ASCII-art titles (optional)
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
uv add "usecli[figlet]"
|
|
74
|
+
# or: pip install "usecli[figlet]"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The extra installs [pyfiglet](https://github.com/pwaller/pyfiglet). With it,
|
|
78
|
+
`usecli init` offers a figlet font picker and banners are rendered in the
|
|
79
|
+
chosen font. Without it, the picker is skipped and banners print as colored
|
|
80
|
+
text: title and version on one line, description below.
|
|
81
|
+
|
|
70
82
|
### Create a command
|
|
71
83
|
|
|
72
84
|
```sh
|
|
@@ -111,10 +123,16 @@ usecli ma:co # make:command
|
|
|
111
123
|
### Interactive Mode
|
|
112
124
|
|
|
113
125
|
```sh
|
|
114
|
-
usecli --interactive #
|
|
126
|
+
usecli --interactive # Searchable picker for all commands
|
|
115
127
|
usecli -i hello # Run 'hello' command interactively
|
|
116
128
|
```
|
|
117
129
|
|
|
130
|
+
The picker opens in-place with vim-style keys: `j`/`k` or the arrow keys move,
|
|
131
|
+
`/` starts search, and enter runs the highlighted command. `esc` leaves search
|
|
132
|
+
mode but keeps the filter active (normal-mode navigation still works); `ctrl-u`
|
|
133
|
+
clears the filter. Command names, descriptions, the title and the status bar use
|
|
134
|
+
your theme colors; the highlighted row switches to the theme's highlight style.
|
|
135
|
+
|
|
118
136
|
### Command Groups
|
|
119
137
|
|
|
120
138
|
Colon-separated commands group automatically in help:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "usecli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "A powerful Python CLI framework for building beautiful, developer-friendly command-line tools."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -12,9 +12,7 @@ classifiers = [
|
|
|
12
12
|
dependencies = [
|
|
13
13
|
"case-converter>=1.2.0",
|
|
14
14
|
"click>=8.4.2",
|
|
15
|
-
"fzf-bin>=0.74.1",
|
|
16
15
|
"jinja2>=3.1.6",
|
|
17
|
-
"pyfiglet>=1.0.4",
|
|
18
16
|
"rich>=15.0.0",
|
|
19
17
|
"simple-term-menu>=1.6.6",
|
|
20
18
|
"tomli>=2.4.1",
|
|
@@ -28,6 +26,7 @@ name = "Edward Boswell"
|
|
|
28
26
|
email = "thememium@gmail.com"
|
|
29
27
|
|
|
30
28
|
[project.optional-dependencies]
|
|
29
|
+
figlet = ["pyfiglet>=1.0.4"]
|
|
31
30
|
pyinstaller = ["pyinstaller>=6.21.0"]
|
|
32
31
|
|
|
33
32
|
[project.urls]
|
|
@@ -50,6 +49,7 @@ dev = [
|
|
|
50
49
|
"deptry>=0.25.1",
|
|
51
50
|
"isort>=8.0.1",
|
|
52
51
|
"poethepoet>=0.48.0",
|
|
52
|
+
"pyfiglet>=1.0.4",
|
|
53
53
|
"pyinstaller>=6.21.0",
|
|
54
54
|
"pytest>=9.1.1",
|
|
55
55
|
"pytest-cov>=7.1.0",
|
|
@@ -63,11 +63,8 @@ known_first_party = ["usecli"]
|
|
|
63
63
|
[tool.deptry.package_module_name_map]
|
|
64
64
|
case-converter = "caseconverter"
|
|
65
65
|
|
|
66
|
-
[tool.deptry.per_rule_ignores]
|
|
67
|
-
DEP002 = ["fzf-bin"]
|
|
68
|
-
|
|
69
66
|
[tool.poe.tasks]
|
|
70
|
-
dev = "uv run usecli"
|
|
67
|
+
dev = "uv run usecli -i"
|
|
71
68
|
clean-full = "sh -c 'uv run isort . && uv run ruff check . --fix && uv run ruff format . && uv run deptry . && uv run ty check'"
|
|
72
69
|
clean = "sh -c 'uv run isort . && uv run ruff format .'"
|
|
73
70
|
test = "uv run pytest tests/ -v"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "usecli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "A powerful Python CLI framework for building beautiful, developer-friendly command-line tools."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "Edward Boswell", email = "thememium@gmail.com" }]
|
|
@@ -13,9 +13,7 @@ classifiers = [
|
|
|
13
13
|
dependencies = [
|
|
14
14
|
"case-converter>=1.2.0",
|
|
15
15
|
"click>=8.4.2",
|
|
16
|
-
"fzf-bin>=0.74.1",
|
|
17
16
|
"jinja2>=3.1.6",
|
|
18
|
-
"pyfiglet>=1.0.4",
|
|
19
17
|
"rich>=15.0.0",
|
|
20
18
|
"simple-term-menu>=1.6.6",
|
|
21
19
|
"tomli>=2.4.1",
|
|
@@ -25,6 +23,7 @@ license = "MIT"
|
|
|
25
23
|
license-files = ["LICEN[CS]E*"]
|
|
26
24
|
|
|
27
25
|
[project.optional-dependencies]
|
|
26
|
+
figlet = ["pyfiglet>=1.0.4"]
|
|
28
27
|
pyinstaller = ["pyinstaller>=6.21.0"]
|
|
29
28
|
|
|
30
29
|
[project.urls]
|
|
@@ -47,6 +46,7 @@ dev = [
|
|
|
47
46
|
"deptry>=0.25.1",
|
|
48
47
|
"isort>=8.0.1",
|
|
49
48
|
"poethepoet>=0.48.0",
|
|
49
|
+
"pyfiglet>=1.0.4",
|
|
50
50
|
"pyinstaller>=6.21.0",
|
|
51
51
|
"pytest>=9.1.1",
|
|
52
52
|
"pytest-cov>=7.1.0",
|
|
@@ -60,11 +60,8 @@ known_first_party = ["usecli"]
|
|
|
60
60
|
[tool.deptry.package_module_name_map]
|
|
61
61
|
case-converter = "caseconverter"
|
|
62
62
|
|
|
63
|
-
[tool.deptry.per_rule_ignores]
|
|
64
|
-
DEP002 = ["fzf-bin"]
|
|
65
|
-
|
|
66
63
|
[tool.poe.tasks]
|
|
67
|
-
dev = "uv run usecli"
|
|
64
|
+
dev = "uv run usecli -i"
|
|
68
65
|
clean-full = "sh -c 'uv run isort . && uv run ruff check . --fix && uv run ruff format . && uv run deptry . && uv run ty check'"
|
|
69
66
|
clean = "sh -c 'uv run isort . && uv run ruff format .'"
|
|
70
67
|
test = "uv run pytest tests/ -v"
|
|
@@ -572,7 +572,7 @@ def _get_run_app_callback():
|
|
|
572
572
|
raise NonInteractiveError("Interactive mode is unavailable in JSON mode")
|
|
573
573
|
|
|
574
574
|
if interactive_requested:
|
|
575
|
-
from usecli.cli.commands.defaults.base.internal.
|
|
575
|
+
from usecli.cli.commands.defaults.base.internal.interactive_command import (
|
|
576
576
|
run_interactive,
|
|
577
577
|
)
|
|
578
578
|
|
|
@@ -30,6 +30,7 @@ PyInstaller is an optional dependency — install it with
|
|
|
30
30
|
|
|
31
31
|
from __future__ import annotations
|
|
32
32
|
|
|
33
|
+
import importlib.util
|
|
33
34
|
import os
|
|
34
35
|
import sys
|
|
35
36
|
import zipfile
|
|
@@ -100,11 +101,10 @@ def _build_args(
|
|
|
100
101
|
args += ["--distpath", str(distpath)]
|
|
101
102
|
if workpath is not None:
|
|
102
103
|
args += ["--workpath", str(workpath)]
|
|
104
|
+
args += ["--collect-all", "usecli"]
|
|
105
|
+
if importlib.util.find_spec("pyfiglet") is not None:
|
|
106
|
+
args += ["--collect-all", "pyfiglet"]
|
|
103
107
|
args += [
|
|
104
|
-
"--collect-all",
|
|
105
|
-
"usecli",
|
|
106
|
-
"--collect-all",
|
|
107
|
-
"pyfiglet",
|
|
108
108
|
"--add-data",
|
|
109
109
|
f"{data_root}{os.pathsep}{BUNDLE_DATA_DIR}",
|
|
110
110
|
"--paths",
|
|
@@ -6,16 +6,11 @@ import random
|
|
|
6
6
|
|
|
7
7
|
from usecli.cli.config.colors import COLOR
|
|
8
8
|
from usecli.cli.core.base_command import BaseCommand
|
|
9
|
-
from usecli.shared.config.manager import get_config
|
|
10
9
|
|
|
11
10
|
|
|
12
11
|
class InspireCommand(BaseCommand):
|
|
13
12
|
"""Command for displaying random inspirational quotes."""
|
|
14
13
|
|
|
15
|
-
def visible(self) -> bool:
|
|
16
|
-
config = get_config()
|
|
17
|
-
return not config.get("hide_inspire", False)
|
|
18
|
-
|
|
19
14
|
def signature(self) -> str:
|
|
20
15
|
"""Return the command signature."""
|
|
21
16
|
return "inspire"
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Interactive command picker for the usecli CLI.
|
|
2
|
+
|
|
3
|
+
The picker is built on :mod:`simple_term_menu` — the same widget used elsewhere
|
|
4
|
+
in usecli — so ``--interactive`` works without an external fuzzy-finder binary.
|
|
5
|
+
It keeps the fzf feel: vim-style navigation (``j``/``k`` or arrows), ``/`` to
|
|
6
|
+
search and a styled cursor.
|
|
7
|
+
"""
|
|
2
8
|
|
|
3
9
|
from __future__ import annotations
|
|
4
10
|
|
|
@@ -7,6 +13,7 @@ import os
|
|
|
7
13
|
import shutil
|
|
8
14
|
import subprocess
|
|
9
15
|
import sys
|
|
16
|
+
from collections.abc import Callable
|
|
10
17
|
from pathlib import Path
|
|
11
18
|
from typing import TYPE_CHECKING, Any, cast
|
|
12
19
|
|
|
@@ -16,7 +23,6 @@ from rich.console import Console
|
|
|
16
23
|
from rich.prompt import Confirm, IntPrompt
|
|
17
24
|
|
|
18
25
|
from usecli.cli.config.colors import COLOR
|
|
19
|
-
from usecli.cli.core.base_command import BaseCommand
|
|
20
26
|
from usecli.cli.core.error.handler import ErrorHandler
|
|
21
27
|
from usecli.cli.core.exceptions import UsecliError
|
|
22
28
|
from usecli.cli.core.ui import is_click_group
|
|
@@ -27,6 +33,8 @@ if TYPE_CHECKING:
|
|
|
27
33
|
|
|
28
34
|
console = Console()
|
|
29
35
|
|
|
36
|
+
_STATUS_BAR = "↑↓/j/k move · / search · ctrl-u clear · ⏎ run · esc cancel"
|
|
37
|
+
|
|
30
38
|
|
|
31
39
|
def _get_required_arguments(command: ClickCommand) -> list[tuple[str, str, type]]:
|
|
32
40
|
callback = command.callback
|
|
@@ -113,55 +121,132 @@ def _get_optional_options(
|
|
|
113
121
|
return options
|
|
114
122
|
|
|
115
123
|
|
|
116
|
-
def
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
def _clean_text(text: str) -> str:
|
|
125
|
+
"""Collapse whitespace so a description fits on one menu line."""
|
|
126
|
+
return " ".join(text.split())
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _humanize_name(name: str) -> str:
|
|
130
|
+
"""Build a readable fallback description for a command with no help text."""
|
|
131
|
+
words = name.replace(":", " ").replace("-", " ").replace("_", " ").split()
|
|
132
|
+
return " ".join(words).capitalize()
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _fit(text: str, width: int) -> str:
|
|
136
|
+
"""Truncate text to ``width`` columns, adding an ellipsis when cut."""
|
|
137
|
+
if width <= 0:
|
|
138
|
+
return ""
|
|
139
|
+
if len(text) <= width:
|
|
140
|
+
return text
|
|
141
|
+
if width == 1:
|
|
142
|
+
return "…"
|
|
143
|
+
return text[: width - 1].rstrip() + "…"
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _menu_entry(name: str, description: str, name_width: int) -> str:
|
|
147
|
+
"""Render one two-column menu entry."""
|
|
148
|
+
if description:
|
|
149
|
+
display = f"{name:<{name_width}} {description}".rstrip()
|
|
150
|
+
else:
|
|
151
|
+
display = name
|
|
152
|
+
|
|
153
|
+
# simple-term-menu treats an unescaped ``|`` as a preview-argument
|
|
154
|
+
# separator, so escape it to keep it visible in the row.
|
|
155
|
+
return display.replace("|", "\\|")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _run_command_menu(
|
|
159
|
+
entries: list[str],
|
|
160
|
+
*,
|
|
161
|
+
title: str,
|
|
162
|
+
entry_renderer: Callable[[str], str] | None = None,
|
|
119
163
|
) -> str | None:
|
|
120
|
-
|
|
121
|
-
selection = terminal_menu(options, title=prompt.strip())
|
|
122
|
-
return selection[0] if selection else None
|
|
123
|
-
|
|
124
|
-
input_data = "\n".join(options)
|
|
125
|
-
|
|
126
|
-
fzf_args = [
|
|
127
|
-
"fzf",
|
|
128
|
-
"--ansi",
|
|
129
|
-
f"--prompt={prompt}",
|
|
130
|
-
f"--color=prompt:{COLOR.SECONDARY}",
|
|
131
|
-
"--layout=reverse",
|
|
132
|
-
"--height=~40%",
|
|
133
|
-
"--border",
|
|
134
|
-
f"--color=border:{COLOR.PRIMARY}",
|
|
135
|
-
"--bind=ctrl-d:half-page-down",
|
|
136
|
-
"--bind=ctrl-u:half-page-up",
|
|
137
|
-
]
|
|
164
|
+
"""Show the interactive picker and return the selected entry.
|
|
138
165
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
166
|
+
Returns ``None`` when the user cancels. Raises :class:`UsecliError` when
|
|
167
|
+
there is no terminal to draw the menu on.
|
|
168
|
+
"""
|
|
169
|
+
if not entries:
|
|
170
|
+
return None
|
|
171
|
+
|
|
172
|
+
if not sys.stdin.isatty() or not sys.stdout.isatty():
|
|
173
|
+
raise UsecliError(
|
|
174
|
+
"Interactive mode requires a terminal",
|
|
175
|
+
suggestion=(
|
|
176
|
+
"Run the command with explicit arguments instead of using "
|
|
177
|
+
"--interactive."
|
|
178
|
+
),
|
|
146
179
|
)
|
|
147
180
|
|
|
148
|
-
|
|
149
|
-
|
|
181
|
+
selection = terminal_menu(
|
|
182
|
+
entries,
|
|
183
|
+
title=title,
|
|
184
|
+
search=True,
|
|
185
|
+
search_key="/",
|
|
186
|
+
vim_search=True,
|
|
187
|
+
status_bar=_STATUS_BAR,
|
|
188
|
+
title_style=COLOR.ANSI.SECONDARY,
|
|
189
|
+
entry_renderer=entry_renderer,
|
|
190
|
+
)
|
|
191
|
+
if not selection:
|
|
192
|
+
return None
|
|
150
193
|
|
|
151
|
-
|
|
152
|
-
ErrorHandler.display_error(
|
|
153
|
-
f"fzf error: {result.stderr}",
|
|
154
|
-
suggestion="Check fzf installation and try again",
|
|
155
|
-
)
|
|
156
|
-
raise typer.Exit(code=1)
|
|
194
|
+
return selection[0]
|
|
157
195
|
|
|
158
|
-
return result.stdout.strip()
|
|
159
196
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
197
|
+
def _select_command(
|
|
198
|
+
commands: list[dict[str, Any]],
|
|
199
|
+
*,
|
|
200
|
+
title: str,
|
|
201
|
+
) -> str | None:
|
|
202
|
+
"""Show a picker for ``commands`` and return the selected name."""
|
|
203
|
+
if not commands:
|
|
204
|
+
return None
|
|
205
|
+
|
|
206
|
+
name_width = max(len(cmd["name"]) for cmd in commands)
|
|
207
|
+
terminal_width = shutil.get_terminal_size((80, 24)).columns
|
|
208
|
+
|
|
209
|
+
name_color = COLOR.ANSI.PRIMARY
|
|
210
|
+
description_color = COLOR.ANSI.FOREGROUND_MUTED
|
|
211
|
+
reset = COLOR.ANSI.RESET
|
|
212
|
+
color_overhead = len(name_color) + len(description_color) + 2 * len(reset)
|
|
213
|
+
plain_description_width = max(20, terminal_width - name_width - 6)
|
|
214
|
+
available_for_description = plain_description_width - color_overhead
|
|
215
|
+
use_colors = bool(name_color and description_color and reset) and (
|
|
216
|
+
available_for_description >= 20
|
|
217
|
+
)
|
|
218
|
+
description_width = (
|
|
219
|
+
available_for_description if use_colors else plain_description_width
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
entries: list[str] = []
|
|
223
|
+
name_by_entry: dict[str, str] = {}
|
|
224
|
+
colored_entries: dict[str, str] = {}
|
|
225
|
+
for cmd in commands:
|
|
226
|
+
description = _fit(
|
|
227
|
+
_clean_text(cmd["help"]) or _humanize_name(cmd["name"]),
|
|
228
|
+
description_width,
|
|
164
229
|
)
|
|
230
|
+
entry = _menu_entry(cmd["name"], description, name_width)
|
|
231
|
+
entries.append(entry)
|
|
232
|
+
name_by_entry[entry] = cmd["name"]
|
|
233
|
+
if use_colors:
|
|
234
|
+
padded_name = f"{cmd['name']:<{name_width}}"
|
|
235
|
+
if description:
|
|
236
|
+
colored_entries[entry] = (
|
|
237
|
+
f"{name_color}{padded_name}{reset} "
|
|
238
|
+
f"{description_color}{description}{reset}"
|
|
239
|
+
)
|
|
240
|
+
else:
|
|
241
|
+
colored_entries[entry] = f"{name_color}{padded_name}{reset}"
|
|
242
|
+
|
|
243
|
+
entry_renderer = (
|
|
244
|
+
(lambda entry: colored_entries.get(entry, entry)) if colored_entries else None
|
|
245
|
+
)
|
|
246
|
+
selected = _run_command_menu(entries, title=title, entry_renderer=entry_renderer)
|
|
247
|
+
if selected is None:
|
|
248
|
+
return None
|
|
249
|
+
return name_by_entry.get(selected)
|
|
165
250
|
|
|
166
251
|
|
|
167
252
|
def _resolve_group_alias(app: typer.Typer, group_name: str) -> str:
|
|
@@ -244,43 +329,31 @@ def run_interactive(
|
|
|
244
329
|
section_cmds.sort(key=lambda x: x["name"])
|
|
245
330
|
sorted_sections = sorted(sections.items(), key=lambda x: x[0])
|
|
246
331
|
|
|
247
|
-
for group_name, group_help in groups.items():
|
|
332
|
+
for group_name, group_help in sorted(groups.items()):
|
|
248
333
|
top_level.append({"name": group_name, "help": group_help, "is_group": True})
|
|
249
334
|
|
|
250
335
|
ordered_commands = top_level + [
|
|
251
336
|
cmd for _, section_cmds in sorted_sections for cmd in section_cmds
|
|
252
337
|
]
|
|
253
|
-
max_name_len = max(len(cmd["name"]) for cmd in ordered_commands)
|
|
254
|
-
|
|
255
|
-
def build_option_line(cmd: dict[str, Any], padding_len: int) -> str:
|
|
256
|
-
padding = " " * padding_len
|
|
257
|
-
return (
|
|
258
|
-
f"{COLOR.ANSI.PRIMARY}{cmd['name']}{COLOR.ANSI.RESET}"
|
|
259
|
-
f"{padding}{COLOR.ANSI.FOREGROUND_MUTED}{cmd['help']}{COLOR.ANSI.RESET}"
|
|
260
|
-
)
|
|
261
338
|
|
|
262
339
|
cmd_name: str | None = None
|
|
263
340
|
selected_cmd: dict[str, Any] | None = None
|
|
264
341
|
|
|
265
342
|
if not cmd_parts:
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
selection = _run_fzf_menu(options, prompt=f"{script_name} » ")
|
|
272
|
-
if selection is None:
|
|
343
|
+
cmd_name = _select_command(
|
|
344
|
+
ordered_commands,
|
|
345
|
+
title=f"{script_name} » select a command",
|
|
346
|
+
)
|
|
347
|
+
if cmd_name is None:
|
|
273
348
|
ErrorHandler.display_warning("No command selected")
|
|
274
349
|
return
|
|
275
350
|
|
|
276
|
-
cmd_name = selection.split()[0] if selection else None
|
|
277
|
-
if not cmd_name:
|
|
278
|
-
ErrorHandler.display_error("Could not parse command")
|
|
279
|
-
raise typer.Exit(code=1)
|
|
280
|
-
|
|
281
351
|
selected_cmd = next(
|
|
282
352
|
(c for c in ordered_commands if c["name"] == cmd_name), None
|
|
283
353
|
)
|
|
354
|
+
if not selected_cmd:
|
|
355
|
+
ErrorHandler.display_error(f"Unknown command '{cmd_name}'")
|
|
356
|
+
raise typer.Exit(code=1)
|
|
284
357
|
else:
|
|
285
358
|
cmd_name = cmd_parts[0]
|
|
286
359
|
selected_cmd = next(
|
|
@@ -304,24 +377,18 @@ def run_interactive(
|
|
|
304
377
|
raise typer.Exit(code=1)
|
|
305
378
|
|
|
306
379
|
subcommands.sort(key=lambda x: x["name"])
|
|
307
|
-
max_sub_name_len = max(len(cmd["name"]) for cmd in subcommands)
|
|
308
380
|
|
|
309
381
|
sub_name: str | None = None
|
|
310
382
|
if cmd_parts and len(cmd_parts) > 1:
|
|
311
383
|
sub_name = cmd_parts[1]
|
|
312
384
|
else:
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
sub_options.append(build_option_line(cmd, padding_len))
|
|
317
|
-
|
|
318
|
-
sub_selection = _run_fzf_menu(
|
|
319
|
-
sub_options, prompt=f"{script_name} {cmd_name} » "
|
|
385
|
+
sub_name = _select_command(
|
|
386
|
+
subcommands,
|
|
387
|
+
title=f"{script_name} {cmd_name} » select a subcommand",
|
|
320
388
|
)
|
|
321
|
-
if
|
|
389
|
+
if sub_name is None:
|
|
322
390
|
ErrorHandler.display_warning("No subcommand selected")
|
|
323
391
|
return
|
|
324
|
-
sub_name = sub_selection.split()[0] if sub_selection else None
|
|
325
392
|
|
|
326
393
|
if not sub_name:
|
|
327
394
|
ErrorHandler.display_error("Could not parse subcommand")
|
|
@@ -528,31 +595,3 @@ def run_interactive(
|
|
|
528
595
|
console.print()
|
|
529
596
|
|
|
530
597
|
subprocess.run(full_cmd, shell=True, check=False)
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
_EXTRA_ARGS_DEFAULT = typer.Argument(
|
|
534
|
-
None, help="Additional arguments to pass to the selected command"
|
|
535
|
-
)
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
class FzfCommand(BaseCommand):
|
|
539
|
-
"""Interactive command finder using fzf."""
|
|
540
|
-
|
|
541
|
-
def signature(self) -> str:
|
|
542
|
-
"""Return the command signature."""
|
|
543
|
-
return "fzf"
|
|
544
|
-
|
|
545
|
-
def description(self) -> str:
|
|
546
|
-
"""Return the command description."""
|
|
547
|
-
return "Interactive command finder using fzf"
|
|
548
|
-
|
|
549
|
-
def handle(
|
|
550
|
-
self,
|
|
551
|
-
extra_args: list[str] = _EXTRA_ARGS_DEFAULT,
|
|
552
|
-
) -> None:
|
|
553
|
-
"""Handle the fzf command execution.
|
|
554
|
-
|
|
555
|
-
Args:
|
|
556
|
-
extra_args: Additional arguments to pass to the selected command.
|
|
557
|
-
"""
|
|
558
|
-
run_interactive(self.app, extra_args=extra_args)
|