slashed 1.0.6__tar.gz → 1.0.7__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.
- {slashed-1.0.6 → slashed-1.0.7}/PKG-INFO +1 -1
- {slashed-1.0.6 → slashed-1.0.7}/pyproject.toml +1 -1
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/commands.py +68 -45
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/completers.py +3 -11
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/store.py +2 -6
- {slashed-1.0.6 → slashed-1.0.7}/LICENSE +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/README.md +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/__init__.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/base.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/builtin/__init__.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/builtin/help_cmd.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/builtin/system.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/completion.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/context.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/events.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/exceptions.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/log.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/output.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/prompt_toolkit_completer.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/py.typed +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/registry.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/router.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/slashed_types.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/textual_adapter/__init__.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/textual_adapter/app.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/textual_adapter/command_base.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/textual_adapter/command_input.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/textual_adapter/command_textarea.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/textual_adapter/dropdown.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/textual_adapter/log.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/textual_adapter/suggester.py +0 -0
- {slashed-1.0.6 → slashed-1.0.7}/src/slashed/utils.py +0 -0
|
@@ -111,54 +111,77 @@ class SlashedCommand(BaseCommand):
|
|
|
111
111
|
):
|
|
112
112
|
"""Execute command by binding command-line arguments to method parameters."""
|
|
113
113
|
method = type(self).execute_command
|
|
114
|
-
|
|
115
|
-
#
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
# Check if we need to pass context
|
|
119
|
-
param_names = list(parameters.keys())
|
|
120
|
-
has_ctx = param_names and _is_context_param(param_names[0], method)
|
|
121
|
-
|
|
122
|
-
# Prepare parameters for matching, excluding context if present
|
|
123
|
-
if has_ctx:
|
|
124
|
-
ctx_param_name = param_names[0]
|
|
125
|
-
parameters_for_matching = {
|
|
126
|
-
k: v for k, v in parameters.items() if k != ctx_param_name
|
|
127
|
-
}
|
|
128
|
-
call_args: list[str | CommandContext] = [ctx] # Add context as first argument
|
|
129
|
-
else:
|
|
130
|
-
parameters_for_matching = parameters
|
|
131
|
-
call_args = [] # No context parameter
|
|
132
|
-
|
|
133
|
-
# Get required parameters in order (excluding context if applicable)
|
|
134
|
-
required = [
|
|
135
|
-
name
|
|
136
|
-
for name, param in parameters_for_matching.items()
|
|
137
|
-
if param.default == inspect.Parameter.empty
|
|
138
|
-
]
|
|
139
|
-
|
|
140
|
-
# Check if required args are provided either as positional or keyword
|
|
141
|
-
missing = [
|
|
142
|
-
name
|
|
143
|
-
for idx, name in enumerate(required)
|
|
144
|
-
if name not in kwargs and len(args) < idx + 1
|
|
145
|
-
]
|
|
146
|
-
|
|
147
|
-
if missing:
|
|
148
|
-
msg = f"Missing required arguments: {missing}"
|
|
149
|
-
raise CommandError(msg)
|
|
114
|
+
call_args = parse_method(method, ctx, args, kwargs)
|
|
115
|
+
# Call with positional args first, then kwargs
|
|
116
|
+
return await self.execute_command(*call_args, **kwargs)
|
|
150
117
|
|
|
151
|
-
# Validate keyword arguments
|
|
152
|
-
for name in kwargs:
|
|
153
|
-
if name not in parameters_for_matching:
|
|
154
|
-
msg = f"Unknown argument: {name}"
|
|
155
|
-
raise CommandError(msg)
|
|
156
118
|
|
|
157
|
-
|
|
158
|
-
|
|
119
|
+
def parse_method(
|
|
120
|
+
method: Callable,
|
|
121
|
+
ctx: CommandContext,
|
|
122
|
+
args: list[str],
|
|
123
|
+
kwargs: dict[str, str],
|
|
124
|
+
) -> list[str | CommandContext]:
|
|
125
|
+
"""Parse method parameters and return a list of positional arguments."""
|
|
126
|
+
sig = inspect.signature(method)
|
|
127
|
+
# Get parameter information (skip self)
|
|
128
|
+
parameters = dict(list(sig.parameters.items())[1:])
|
|
129
|
+
|
|
130
|
+
# Check if we need to pass context
|
|
131
|
+
param_names = list(parameters.keys())
|
|
132
|
+
has_ctx = param_names and _is_context_param(param_names[0], method)
|
|
133
|
+
|
|
134
|
+
# Prepare parameters for matching, excluding context if present
|
|
135
|
+
if has_ctx:
|
|
136
|
+
ctx_param_name = param_names[0]
|
|
137
|
+
parameters_for_matching = {
|
|
138
|
+
k: v for k, v in parameters.items() if k != ctx_param_name
|
|
139
|
+
}
|
|
140
|
+
call_args: list[str | CommandContext] = [ctx] # Add context as first argument
|
|
141
|
+
else:
|
|
142
|
+
parameters_for_matching = parameters
|
|
143
|
+
call_args = [] # No context parameter
|
|
144
|
+
|
|
145
|
+
# Get required and optional parameters in order (excluding context if applicable)
|
|
146
|
+
param_list = list(parameters_for_matching.items())
|
|
147
|
+
required = [
|
|
148
|
+
name for name, param in param_list if param.default == inspect.Parameter.empty
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
# Check for too many positional arguments
|
|
152
|
+
max_positional = len(param_list)
|
|
153
|
+
if len(args) > max_positional:
|
|
154
|
+
param_names = [name for name, _ in param_list]
|
|
155
|
+
msg = f"Too many positional arguments. Expected at most {max_positional} ({param_names}), got {len(args)}" # noqa: E501
|
|
156
|
+
raise CommandError(msg)
|
|
157
|
+
|
|
158
|
+
# Check for conflicts between positional and keyword arguments
|
|
159
|
+
positional_param_names = [name for name, _ in param_list[: len(args)]]
|
|
160
|
+
conflicts = set(positional_param_names) & set(kwargs.keys())
|
|
161
|
+
if conflicts:
|
|
162
|
+
msg = f"Arguments provided both positionally and as keywords: {list(conflicts)}"
|
|
163
|
+
raise CommandError(msg)
|
|
164
|
+
|
|
165
|
+
# Check if required args are provided either as positional or keyword
|
|
166
|
+
missing = [
|
|
167
|
+
name
|
|
168
|
+
for idx, name in enumerate(required)
|
|
169
|
+
if name not in kwargs and len(args) < idx + 1
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
if missing:
|
|
173
|
+
msg = f"Missing required arguments: {missing}"
|
|
174
|
+
raise CommandError(msg)
|
|
175
|
+
|
|
176
|
+
# Validate keyword arguments exist in signature
|
|
177
|
+
for name in kwargs:
|
|
178
|
+
if name not in parameters_for_matching:
|
|
179
|
+
msg = f"Unknown argument: {name}"
|
|
180
|
+
raise CommandError(msg)
|
|
159
181
|
|
|
160
|
-
|
|
161
|
-
|
|
182
|
+
# Add positional arguments
|
|
183
|
+
call_args.extend(args)
|
|
184
|
+
return call_args
|
|
162
185
|
|
|
163
186
|
|
|
164
187
|
def extract_usage_params(func: Callable) -> list[str]:
|
|
@@ -2,22 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from collections.abc import Awaitable, Iterable
|
|
5
6
|
from copy import copy
|
|
6
7
|
import inspect
|
|
7
8
|
import os
|
|
8
|
-
from typing import TYPE_CHECKING, Any
|
|
9
|
+
from typing import TYPE_CHECKING, Any, TypeGuard, cast
|
|
9
10
|
|
|
10
11
|
from upath import UPath
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
try:
|
|
14
|
-
from upath import UPath as Path
|
|
15
|
-
except ImportError:
|
|
16
|
-
from pathlib import Path # type: ignore[assignment]
|
|
17
|
-
|
|
18
|
-
from collections.abc import Awaitable, Iterable
|
|
19
|
-
from typing import TypeGuard, cast
|
|
20
|
-
|
|
21
13
|
from slashed import utils
|
|
22
14
|
from slashed.completion import CompletionItem, CompletionProvider
|
|
23
15
|
from slashed.log import get_logger
|
|
@@ -94,7 +86,7 @@ class PathCompleter(CompletionProvider):
|
|
|
94
86
|
# Handle relative paths
|
|
95
87
|
else:
|
|
96
88
|
# If base_path is set, resolve relative to it
|
|
97
|
-
base = self.base_path or
|
|
89
|
+
base = self.base_path or UPath.cwd()
|
|
98
90
|
path = (base / word).resolve()
|
|
99
91
|
|
|
100
92
|
# If path doesn't exist, use its parent for listing
|
|
@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Any, TypeVar
|
|
|
8
8
|
|
|
9
9
|
from psygnal import Signal
|
|
10
10
|
from psygnal.containers import EventedDict
|
|
11
|
+
from upath import UPath
|
|
11
12
|
|
|
12
13
|
from slashed.base import (
|
|
13
14
|
BaseCommand,
|
|
@@ -25,11 +26,6 @@ from slashed.log import get_logger
|
|
|
25
26
|
from slashed.output import CallbackOutputWriter, DefaultOutputWriter
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
try:
|
|
29
|
-
from upath import UPath as Path
|
|
30
|
-
except ImportError:
|
|
31
|
-
from pathlib import Path # type: ignore[assignment]
|
|
32
|
-
|
|
33
29
|
if TYPE_CHECKING:
|
|
34
30
|
from collections.abc import Callable
|
|
35
31
|
import os
|
|
@@ -68,7 +64,7 @@ class CommandStore:
|
|
|
68
64
|
self._commands = EventedDict[str, BaseCommand]()
|
|
69
65
|
self._contexts = ContextRegistry()
|
|
70
66
|
self._command_history: list[str] = []
|
|
71
|
-
self._history_path =
|
|
67
|
+
self._history_path = UPath(history_file) if history_file else None
|
|
72
68
|
self._enable_system_commands = enable_system_commands
|
|
73
69
|
self._initialized = False
|
|
74
70
|
if self._history_path:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|