scriptvault 0.0.1__tar.gz → 0.1.5b0__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.
- {scriptvault-0.0.1/src/scriptvault.egg-info → scriptvault-0.1.5b0}/PKG-INFO +81 -8
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/README.md +80 -7
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/pyproject.toml +4 -1
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault/__init__.py +2 -2
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault/cli.py +252 -53
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault/run.py +31 -14
- scriptvault-0.1.5b0/src/scriptvault/vault.py +654 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0/src/scriptvault.egg-info}/PKG-INFO +81 -8
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/tests/test_add.py +2 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/tests/test_completion.py +7 -0
- scriptvault-0.1.5b0/tests/test_list.py +95 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/tests/test_real.py +9 -1
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/tests/test_run.py +7 -1
- scriptvault-0.0.1/src/scriptvault/vault.py +0 -326
- scriptvault-0.0.1/tests/test_list.py +0 -154
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/LICENSE +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/setup.cfg +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault/__main__.py +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault/envfile.py +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault/templates.py +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault/term.py +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault.egg-info/SOURCES.txt +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault.egg-info/dependency_links.txt +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault.egg-info/entry_points.txt +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault.egg-info/requires.txt +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/src/scriptvault.egg-info/top_level.txt +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/tests/test_edit.py +0 -0
- {scriptvault-0.0.1 → scriptvault-0.1.5b0}/tests/test_init.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scriptvault
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.1.5b0
|
|
4
4
|
Summary: Store and run project commands in a hidden vault directory
|
|
5
5
|
Author: Majwt
|
|
6
6
|
License-Expression: MIT
|
|
@@ -71,18 +71,50 @@ sv list
|
|
|
71
71
|
## Vault layout
|
|
72
72
|
|
|
73
73
|
```text
|
|
74
|
-
.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
.project/
|
|
75
|
+
.sv/
|
|
76
|
+
vault.toml
|
|
77
|
+
.env
|
|
78
|
+
scripts/
|
|
79
|
+
hello.sh
|
|
80
|
+
hello.env
|
|
81
|
+
includes/
|
|
82
|
+
c-hello/
|
|
83
|
+
.sv/
|
|
84
|
+
vault.toml
|
|
85
|
+
scripts/
|
|
86
|
+
build.sh
|
|
80
87
|
```
|
|
81
88
|
|
|
82
|
-
- `vault.toml` defines inline scripts and
|
|
89
|
+
- `vault.toml` defines inline scripts, orchestrations, and nested vault includes.
|
|
83
90
|
- `.env` is the global dotenv file.
|
|
84
91
|
- `scripts/*.sh` are executable file scripts.
|
|
85
92
|
- `scripts/NAME.env` is the per-script dotenv file.
|
|
93
|
+
- `[include.NAME]` sections load scripts from nested vaults (see below).
|
|
94
|
+
|
|
95
|
+
### Nested Vaults
|
|
96
|
+
|
|
97
|
+
Include scripts from subdirectories:
|
|
98
|
+
|
|
99
|
+
```toml
|
|
100
|
+
[vault]
|
|
101
|
+
name = "myproject"
|
|
102
|
+
|
|
103
|
+
[include.c-hello]
|
|
104
|
+
path = "includes/c-hello/.sv/vault.toml"
|
|
105
|
+
|
|
106
|
+
[include.shell]
|
|
107
|
+
path = "includes/shell/.sv/vault.toml"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Run scripts with the include name prefix:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
sv run c-hello build
|
|
114
|
+
sv c-hello build
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Implied run (`sv deploy`) only works for root vault scripts.
|
|
86
118
|
|
|
87
119
|
## Scripts
|
|
88
120
|
|
|
@@ -228,3 +260,44 @@ sv completion fish | source
|
|
|
228
260
|
sv help
|
|
229
261
|
sv --version
|
|
230
262
|
```
|
|
263
|
+
|
|
264
|
+
## Documentation
|
|
265
|
+
|
|
266
|
+
For detailed guides and documentation:
|
|
267
|
+
|
|
268
|
+
- [Vault Activation](docs/VAULT_ACTIVATION.md) - How to activate specific vaults
|
|
269
|
+
- [Nested Vaults](docs/IMPLEMENTATION_SUMMARY.md) - Working with nested vaults
|
|
270
|
+
- [Completion Guide](docs/COMPLETION_REPORT.md) - Shell completion details
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Root Vault Activation
|
|
275
|
+
|
|
276
|
+
When running `sv` from any subdirectory, it automatically uses the root `.sv` directory.
|
|
277
|
+
|
|
278
|
+
See [Vault Activation](docs/VAULT_ACTIVATION.md) for detailed information.
|
|
279
|
+
|
|
280
|
+
## Orchestration with Nested Scripts
|
|
281
|
+
|
|
282
|
+
Orchestrations can reference scripts from included vaults.
|
|
283
|
+
|
|
284
|
+
See [Nested Vaults](docs/IMPLEMENTATION_SUMMARY.md) for examples.
|
|
285
|
+
|
|
286
|
+
## Shell Completion
|
|
287
|
+
|
|
288
|
+
Generate shell completion scripts:
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
# Auto-detect from SHELL environment variable
|
|
292
|
+
sv completion $shell | source
|
|
293
|
+
|
|
294
|
+
# Specify shell explicitly
|
|
295
|
+
sv completion bash | source
|
|
296
|
+
sv completion zsh | source
|
|
297
|
+
sv completion fish | source
|
|
298
|
+
|
|
299
|
+
# Use full path
|
|
300
|
+
sv completion /usr/bin/bash | source
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
See [Shell Completion](docs/COMPLETION_REPORT.md) for details.
|
|
@@ -51,18 +51,50 @@ sv list
|
|
|
51
51
|
## Vault layout
|
|
52
52
|
|
|
53
53
|
```text
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
.project/
|
|
55
|
+
.sv/
|
|
56
|
+
vault.toml
|
|
57
|
+
.env
|
|
58
|
+
scripts/
|
|
59
|
+
hello.sh
|
|
60
|
+
hello.env
|
|
61
|
+
includes/
|
|
62
|
+
c-hello/
|
|
63
|
+
.sv/
|
|
64
|
+
vault.toml
|
|
65
|
+
scripts/
|
|
66
|
+
build.sh
|
|
60
67
|
```
|
|
61
68
|
|
|
62
|
-
- `vault.toml` defines inline scripts and
|
|
69
|
+
- `vault.toml` defines inline scripts, orchestrations, and nested vault includes.
|
|
63
70
|
- `.env` is the global dotenv file.
|
|
64
71
|
- `scripts/*.sh` are executable file scripts.
|
|
65
72
|
- `scripts/NAME.env` is the per-script dotenv file.
|
|
73
|
+
- `[include.NAME]` sections load scripts from nested vaults (see below).
|
|
74
|
+
|
|
75
|
+
### Nested Vaults
|
|
76
|
+
|
|
77
|
+
Include scripts from subdirectories:
|
|
78
|
+
|
|
79
|
+
```toml
|
|
80
|
+
[vault]
|
|
81
|
+
name = "myproject"
|
|
82
|
+
|
|
83
|
+
[include.c-hello]
|
|
84
|
+
path = "includes/c-hello/.sv/vault.toml"
|
|
85
|
+
|
|
86
|
+
[include.shell]
|
|
87
|
+
path = "includes/shell/.sv/vault.toml"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Run scripts with the include name prefix:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
sv run c-hello build
|
|
94
|
+
sv c-hello build
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Implied run (`sv deploy`) only works for root vault scripts.
|
|
66
98
|
|
|
67
99
|
## Scripts
|
|
68
100
|
|
|
@@ -208,3 +240,44 @@ sv completion fish | source
|
|
|
208
240
|
sv help
|
|
209
241
|
sv --version
|
|
210
242
|
```
|
|
243
|
+
|
|
244
|
+
## Documentation
|
|
245
|
+
|
|
246
|
+
For detailed guides and documentation:
|
|
247
|
+
|
|
248
|
+
- [Vault Activation](docs/VAULT_ACTIVATION.md) - How to activate specific vaults
|
|
249
|
+
- [Nested Vaults](docs/IMPLEMENTATION_SUMMARY.md) - Working with nested vaults
|
|
250
|
+
- [Completion Guide](docs/COMPLETION_REPORT.md) - Shell completion details
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Root Vault Activation
|
|
255
|
+
|
|
256
|
+
When running `sv` from any subdirectory, it automatically uses the root `.sv` directory.
|
|
257
|
+
|
|
258
|
+
See [Vault Activation](docs/VAULT_ACTIVATION.md) for detailed information.
|
|
259
|
+
|
|
260
|
+
## Orchestration with Nested Scripts
|
|
261
|
+
|
|
262
|
+
Orchestrations can reference scripts from included vaults.
|
|
263
|
+
|
|
264
|
+
See [Nested Vaults](docs/IMPLEMENTATION_SUMMARY.md) for examples.
|
|
265
|
+
|
|
266
|
+
## Shell Completion
|
|
267
|
+
|
|
268
|
+
Generate shell completion scripts:
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Auto-detect from SHELL environment variable
|
|
272
|
+
sv completion $shell | source
|
|
273
|
+
|
|
274
|
+
# Specify shell explicitly
|
|
275
|
+
sv completion bash | source
|
|
276
|
+
sv completion zsh | source
|
|
277
|
+
sv completion fish | source
|
|
278
|
+
|
|
279
|
+
# Use full path
|
|
280
|
+
sv completion /usr/bin/bash | source
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
See [Shell Completion](docs/COMPLETION_REPORT.md) for details.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "scriptvault"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.1.5-beta"
|
|
8
8
|
description = "Store and run project commands in a hidden vault directory"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -26,6 +26,9 @@ sv = "scriptvault.cli:main"
|
|
|
26
26
|
[project.optional-dependencies]
|
|
27
27
|
dev = ["pytest>=8"]
|
|
28
28
|
|
|
29
|
+
[dependency-groups]
|
|
30
|
+
dev = ["pytest>=8"]
|
|
31
|
+
|
|
29
32
|
[tool.setuptools.packages.find]
|
|
30
33
|
where = ["src"]
|
|
31
34
|
|
|
@@ -23,7 +23,7 @@ from .vault import (
|
|
|
23
23
|
load_vault,
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
-
COMMANDS = ("add", "completion", "edit", "help", "init", "list", "run")
|
|
26
|
+
COMMANDS = ("add", "activate", "deactivate", "completion", "edit", "help", "init", "list", "run")
|
|
27
27
|
BUILTIN_COMMANDS = set(COMMANDS) | {"__names"}
|
|
28
28
|
RESERVED_NAMES = BUILTIN_COMMANDS | {"config", "env"}
|
|
29
29
|
|
|
@@ -111,60 +111,110 @@ def cmd_list(args: argparse.Namespace) -> int:
|
|
|
111
111
|
|
|
112
112
|
if args.json:
|
|
113
113
|
json.dump(
|
|
114
|
-
|
|
114
|
+
{
|
|
115
|
+
"vault": vault.name,
|
|
116
|
+
"scripts": [_target_json(target) for target in vault.targets.values()],
|
|
117
|
+
"includes": {
|
|
118
|
+
name: {
|
|
119
|
+
"path": str(vault._nested_vaults[name].root),
|
|
120
|
+
"scripts": list(vault._nested_vaults[name].scripts.keys()),
|
|
121
|
+
}
|
|
122
|
+
for name in vault._nested_vaults
|
|
123
|
+
},
|
|
124
|
+
},
|
|
115
125
|
sys.stdout,
|
|
116
126
|
indent=2,
|
|
117
127
|
)
|
|
118
128
|
sys.stdout.write("\n")
|
|
119
129
|
return 0
|
|
120
130
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if
|
|
130
|
-
print("
|
|
131
|
-
|
|
131
|
+
# Show nested structure
|
|
132
|
+
print(f"Root vault: {vault.name}")
|
|
133
|
+
|
|
134
|
+
# Root scripts only (exclude nested vault names)
|
|
135
|
+
root_scripts = [name for name in vault.scripts.keys() if name not in vault._nested_vaults]
|
|
136
|
+
if root_scripts:
|
|
137
|
+
print(f" Scripts: {', '.join(root_scripts)}")
|
|
138
|
+
|
|
139
|
+
if vault._nested_vaults:
|
|
140
|
+
print(f"\nIncluded vaults:")
|
|
141
|
+
for include_name, nested_vault in vault._nested_vaults.items():
|
|
142
|
+
scripts = [name for name in nested_vault.scripts.keys() if name not in vault._nested_vaults]
|
|
143
|
+
if scripts:
|
|
144
|
+
print(f" {include_name}: {', '.join(scripts)}")
|
|
145
|
+
|
|
146
|
+
# If --nested flag is set, show more details
|
|
147
|
+
if args.nested:
|
|
148
|
+
print("\nAll scripts (including nested):")
|
|
149
|
+
for name, target in vault.targets.items():
|
|
150
|
+
print(f" {name}: {target.description}")
|
|
132
151
|
|
|
133
|
-
header = ("NAME", "KIND", "DESCRIPTION")
|
|
134
|
-
widths = [
|
|
135
|
-
max(len(header[i]), *(len(row[i]) for row in rows)) for i in range(3)
|
|
136
|
-
]
|
|
137
|
-
palette = Palette(sys.stdout)
|
|
138
|
-
for is_header, row in enumerate((header, *rows)):
|
|
139
|
-
parts = []
|
|
140
|
-
for i, cell in enumerate(row):
|
|
141
|
-
plain = cell if i == len(row) - 1 else cell.ljust(widths[i])
|
|
142
|
-
if palette.enabled and is_header == 0:
|
|
143
|
-
parts.append(palette.paint(plain, bold=True))
|
|
144
|
-
elif palette.enabled and i == 0:
|
|
145
|
-
parts.append(palette.paint(plain, bold=True))
|
|
146
|
-
elif palette.enabled and i == 1:
|
|
147
|
-
fg = MAGENTA if cell == "orchestration" else GREEN
|
|
148
|
-
parts.append(palette.paint(plain, fg=fg))
|
|
149
|
-
else:
|
|
150
|
-
parts.append(plain)
|
|
151
|
-
print(" ".join(parts))
|
|
152
152
|
return 0
|
|
153
153
|
|
|
154
154
|
|
|
155
|
+
def _parse_args(args: list[str], prefix: str = "--") -> tuple[list[str], list[str]]:
|
|
156
|
+
"""Parse arguments into global flags (without --) and script args (with --)."""
|
|
157
|
+
global_flags = []
|
|
158
|
+
script_args = []
|
|
159
|
+
for arg in args:
|
|
160
|
+
if arg.startswith(prefix):
|
|
161
|
+
script_args.append(arg)
|
|
162
|
+
else:
|
|
163
|
+
global_flags.append(arg)
|
|
164
|
+
return global_flags, script_args
|
|
165
|
+
|
|
166
|
+
|
|
155
167
|
def cmd_run(args: argparse.Namespace) -> int:
|
|
156
168
|
"""Run a script or orchestration from the vault."""
|
|
157
169
|
vault = _load_vault(None)
|
|
158
|
-
|
|
170
|
+
name = args.name
|
|
171
|
+
run_args = list(args.args or [])
|
|
172
|
+
|
|
173
|
+
# Check if this is a nested vault command
|
|
174
|
+
if name in vault._nested_vaults:
|
|
175
|
+
# Nested vault: need at least one more arg for script name
|
|
176
|
+
if not run_args:
|
|
177
|
+
available_includes = ", ".join(vault._nested_vaults.keys())
|
|
178
|
+
raise CLIError(
|
|
179
|
+
f"include {name!r} requires a script name.\n"
|
|
180
|
+
f"Use: sv run {name} <script-name>\n"
|
|
181
|
+
f"Available includes: {available_includes}"
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
script_name = run_args[0]
|
|
185
|
+
run_args = run_args[1:]
|
|
186
|
+
|
|
187
|
+
# Try to get from nested vault
|
|
188
|
+
target = vault.get_script_from_nested(name, script_name)
|
|
189
|
+
if target is None:
|
|
190
|
+
available = ", ".join(vault._nested_vaults[name].targets) or "none"
|
|
191
|
+
raise CLIError(
|
|
192
|
+
f"unknown target {script_name!r} in {name!r} "
|
|
193
|
+
f"(available: {available})", 127
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
# Parse global flags
|
|
197
|
+
global_flags, script_args = _parse_args(run_args, "--")
|
|
198
|
+
return run_target(vault, script_name, script_args, global_flags=global_flags)
|
|
199
|
+
|
|
200
|
+
# Root vault: single arg only
|
|
201
|
+
target = vault.get(name)
|
|
202
|
+
if target is None:
|
|
159
203
|
available = ", ".join(vault.targets) or "none"
|
|
160
204
|
raise CLIError(
|
|
161
|
-
f"unknown target {
|
|
205
|
+
f"unknown target {name!r} (available: {available})", 127
|
|
162
206
|
)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
207
|
+
|
|
208
|
+
# Parse global flags (only if there's a -- separator)
|
|
209
|
+
if "--" in run_args:
|
|
210
|
+
separator_idx = run_args.index("--")
|
|
211
|
+
script_args = run_args[separator_idx + 1:]
|
|
212
|
+
global_flags = run_args[:separator_idx]
|
|
213
|
+
else:
|
|
214
|
+
script_args = run_args
|
|
215
|
+
global_flags = []
|
|
166
216
|
try:
|
|
167
|
-
return run_target(vault,
|
|
217
|
+
return run_target(vault, name, script_args, global_flags=global_flags)
|
|
168
218
|
except OSError as exc:
|
|
169
219
|
detail = exc.strerror or str(exc)
|
|
170
220
|
raise CLIError(f"failed to run {args.name!r}: {detail}")
|
|
@@ -257,7 +307,7 @@ def _select_target(vault) -> str:
|
|
|
257
307
|
if fzf and _interactive():
|
|
258
308
|
try:
|
|
259
309
|
proc = subprocess.run(
|
|
260
|
-
[fzf],
|
|
310
|
+
[fzf, "--height", "40%"],
|
|
261
311
|
input="\n".join(choices) + "\n",
|
|
262
312
|
capture_output=True,
|
|
263
313
|
text=True,
|
|
@@ -336,8 +386,79 @@ _COMPLETIONS = {
|
|
|
336
386
|
|
|
337
387
|
|
|
338
388
|
def cmd_completion(args: argparse.Namespace) -> int:
|
|
339
|
-
"""Print a completion script for the given shell.
|
|
340
|
-
|
|
389
|
+
"""Print a completion script for the given shell.
|
|
390
|
+
|
|
391
|
+
Accepts a shell path (e.g., /usr/bin/bash) or shell name (bash, zsh, fish).
|
|
392
|
+
"""
|
|
393
|
+
shell_path = args.shell
|
|
394
|
+
if not shell_path:
|
|
395
|
+
shell_path = shutil.which('bash') or shutil.which('zsh')
|
|
396
|
+
|
|
397
|
+
# Normalize shell path to basename if it's a full path
|
|
398
|
+
if shell_path.startswith('/'):
|
|
399
|
+
shell_name = os.path.basename(shell_path)
|
|
400
|
+
else:
|
|
401
|
+
shell_name = shell_path
|
|
402
|
+
|
|
403
|
+
# Try to find the shell by path if given
|
|
404
|
+
actual_shell = shutil.which(shell_path) or shutil.which(shell_name)
|
|
405
|
+
if actual_shell:
|
|
406
|
+
shell_name = os.path.basename(actual_shell)
|
|
407
|
+
|
|
408
|
+
if not shell_name or shell_name not in _COMPLETIONS:
|
|
409
|
+
print(f"Error: Shell '{shell_name}' not supported", file=sys.stderr)
|
|
410
|
+
sys.exit(2)
|
|
411
|
+
|
|
412
|
+
print(_COMPLETIONS[shell_name], end="")
|
|
413
|
+
return 0
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def cmd_activate(args: argparse.Namespace) -> int:
|
|
417
|
+
"""Activate a specific vault or deactivate."""
|
|
418
|
+
if args.deactivate:
|
|
419
|
+
# Clear SV_ACTIVE_VAULT (print export for user to source)
|
|
420
|
+
print("export SV_ACTIVE_VAULT=\"\"", file=sys.stderr)
|
|
421
|
+
print("Deactivated. Use this command or pipe to your shell.", file=sys.stderr)
|
|
422
|
+
return 0
|
|
423
|
+
|
|
424
|
+
# Determine which vault to activate
|
|
425
|
+
if args.name is None:
|
|
426
|
+
# Activate current .sv directory (if we're in one)
|
|
427
|
+
current = Path.cwd()
|
|
428
|
+
# Check if current directory IS the .sv directory
|
|
429
|
+
hidden = hidden_dir_name()
|
|
430
|
+
if current.name == hidden and (current / "vault.toml").is_file():
|
|
431
|
+
# We're already in a .sv directory, use it
|
|
432
|
+
vault_name = current.parent.name
|
|
433
|
+
print(f"export SV_ACTIVE_VAULT=\"{vault_name}\"", file=sys.stderr)
|
|
434
|
+
print(f"Activated: {vault_name}", file=sys.stderr)
|
|
435
|
+
else:
|
|
436
|
+
print(f"Error: No vault found in {current}", file=sys.stderr)
|
|
437
|
+
return 1
|
|
438
|
+
else:
|
|
439
|
+
# Activate named vault
|
|
440
|
+
if args.name in RESERVED_NAMES:
|
|
441
|
+
print(f"Error: '{args.name}' is a reserved name", file=sys.stderr)
|
|
442
|
+
return 1
|
|
443
|
+
|
|
444
|
+
current = Path.cwd()
|
|
445
|
+
# Try: current/VAULT/.sv/vault.toml
|
|
446
|
+
vault_path = current / args.name / hidden_dir_name() / "vault.toml"
|
|
447
|
+
if not vault_path.is_file():
|
|
448
|
+
print(f"Error: Vault '{args.name}' not found", file=sys.stderr)
|
|
449
|
+
return 1
|
|
450
|
+
|
|
451
|
+
print(f"export SV_ACTIVE_VAULT=\"{args.name}\"", file=sys.stderr)
|
|
452
|
+
print(f"Activated: {args.name}", file=sys.stderr)
|
|
453
|
+
|
|
454
|
+
# Print the active vault info
|
|
455
|
+
try:
|
|
456
|
+
vault = _load_vault(None)
|
|
457
|
+
print(f"Active vault: {vault.name}", file=sys.stderr)
|
|
458
|
+
except Exception as e:
|
|
459
|
+
print(f"Error loading vault: {e}", file=sys.stderr)
|
|
460
|
+
return 1
|
|
461
|
+
|
|
341
462
|
return 0
|
|
342
463
|
|
|
343
464
|
|
|
@@ -378,32 +499,49 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
378
499
|
"list", help="list scripts and orchestrations in the vault"
|
|
379
500
|
)
|
|
380
501
|
lst.add_argument(
|
|
381
|
-
"path",
|
|
382
|
-
nargs="?",
|
|
383
|
-
default=".",
|
|
502
|
+
"--path",
|
|
384
503
|
metavar="PATH",
|
|
385
|
-
|
|
504
|
+
default=None,
|
|
505
|
+
nargs="?",
|
|
506
|
+
const=".",
|
|
507
|
+
help="path to .sv directory (default: auto-detect root .sv in current or parent directories)",
|
|
508
|
+
)
|
|
509
|
+
lst.add_argument(
|
|
510
|
+
"--json", action="store_true", help="output as a JSON object with include info"
|
|
386
511
|
)
|
|
387
512
|
lst.add_argument(
|
|
388
|
-
"--
|
|
513
|
+
"--nested", action="store_true",
|
|
514
|
+
help="show all nested vault scripts (default: only root scripts)"
|
|
389
515
|
)
|
|
390
516
|
lst.set_defaults(func=cmd_list)
|
|
391
517
|
|
|
392
|
-
run = sub.add_parser("run", help="run a script or orchestration")
|
|
518
|
+
run = sub.add_parser("run", help="run a script or orchestration (prefix with include name for nested vaults, e.g., sv run c-hello build)")
|
|
393
519
|
run.add_argument(
|
|
394
|
-
"
|
|
520
|
+
"--path",
|
|
521
|
+
metavar="PATH",
|
|
522
|
+
default=None,
|
|
523
|
+
help="path to .sv directory (default: auto-detect root .sv in current or parent directories)",
|
|
524
|
+
)
|
|
525
|
+
run.add_argument(
|
|
526
|
+
"name", metavar="NAME", help="script or orchestration to run (for nested vaults, prefix with include name)"
|
|
395
527
|
)
|
|
396
528
|
run.add_argument(
|
|
397
529
|
"args",
|
|
398
530
|
nargs=argparse.REMAINDER,
|
|
399
531
|
metavar="ARG",
|
|
400
|
-
help="arguments to pass to the script
|
|
532
|
+
help="arguments to pass to the script (global flags without -- go to all scripts)",
|
|
401
533
|
)
|
|
402
534
|
run.set_defaults(func=cmd_run)
|
|
403
535
|
|
|
404
536
|
add = sub.add_parser(
|
|
405
537
|
"add", help="create a new file script in the vault"
|
|
406
538
|
)
|
|
539
|
+
add.add_argument(
|
|
540
|
+
"--path",
|
|
541
|
+
metavar="PATH",
|
|
542
|
+
default=None,
|
|
543
|
+
help="path to .sv directory (default: auto-detect root .sv in current or parent directories)",
|
|
544
|
+
)
|
|
407
545
|
add.add_argument(
|
|
408
546
|
"name", metavar="NAME", help="name of the script to create"
|
|
409
547
|
)
|
|
@@ -418,6 +556,12 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
418
556
|
edit = sub.add_parser(
|
|
419
557
|
"edit", help="edit a script, its env, or the vault configuration"
|
|
420
558
|
)
|
|
559
|
+
edit.add_argument(
|
|
560
|
+
"--path",
|
|
561
|
+
metavar="PATH",
|
|
562
|
+
default=None,
|
|
563
|
+
help="path to .sv directory (default: auto-detect root .sv in current or parent directories)",
|
|
564
|
+
)
|
|
421
565
|
edit.add_argument(
|
|
422
566
|
"name",
|
|
423
567
|
nargs="?",
|
|
@@ -433,15 +577,56 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
433
577
|
edit.set_defaults(func=cmd_edit)
|
|
434
578
|
|
|
435
579
|
completion = sub.add_parser(
|
|
436
|
-
"completion", help="print a completion script for
|
|
580
|
+
"completion", help="print a completion script (use $shell for auto-detect from SHELL env)"
|
|
437
581
|
)
|
|
438
582
|
completion.add_argument(
|
|
439
583
|
"shell",
|
|
440
|
-
|
|
441
|
-
help="shell
|
|
584
|
+
metavar="SHELL",
|
|
585
|
+
help="shell path/name (e.g., bash, zsh, fish, /usr/bin/bash, or $shell to auto-detect)",
|
|
442
586
|
)
|
|
443
587
|
completion.set_defaults(func=cmd_completion)
|
|
444
588
|
|
|
589
|
+
activate = sub.add_parser(
|
|
590
|
+
"activate", help="activate a specific vault (sets SV_ACTIVE_VAULT env var)"
|
|
591
|
+
)
|
|
592
|
+
activate.add_argument(
|
|
593
|
+
"name",
|
|
594
|
+
nargs="?",
|
|
595
|
+
default=None,
|
|
596
|
+
metavar="VAULT",
|
|
597
|
+
help="vault name to activate (default: use current .sv directory)",
|
|
598
|
+
)
|
|
599
|
+
activate.add_argument(
|
|
600
|
+
"--deactivate",
|
|
601
|
+
action="store_true",
|
|
602
|
+
help="deactivate any active vault (return to auto-detect)",
|
|
603
|
+
)
|
|
604
|
+
activate.set_defaults(func=cmd_activate)
|
|
605
|
+
|
|
606
|
+
deactivate = sub.add_parser(
|
|
607
|
+
"deactivate", help="deactivate any active vault (return to auto-detect)"
|
|
608
|
+
)
|
|
609
|
+
deactivate.add_argument(
|
|
610
|
+
"--path",
|
|
611
|
+
metavar="PATH",
|
|
612
|
+
default=None,
|
|
613
|
+
help="path to .sv directory (default: auto-detect root .sv in current or parent directories)",
|
|
614
|
+
)
|
|
615
|
+
deactivate.add_argument(
|
|
616
|
+
"--name",
|
|
617
|
+
nargs="?",
|
|
618
|
+
default=None,
|
|
619
|
+
metavar="VAULT",
|
|
620
|
+
help="vault name to activate (default: use current .sv directory)",
|
|
621
|
+
)
|
|
622
|
+
deactivate.add_argument(
|
|
623
|
+
"--deactivate",
|
|
624
|
+
action="store_true",
|
|
625
|
+
default=True,
|
|
626
|
+
help="deactivate any active vault (return to auto-detect)",
|
|
627
|
+
)
|
|
628
|
+
deactivate.set_defaults(func=cmd_activate)
|
|
629
|
+
|
|
445
630
|
return parser
|
|
446
631
|
|
|
447
632
|
|
|
@@ -468,7 +653,21 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
468
653
|
argv = ["run", *argv]
|
|
469
654
|
parser = build_parser()
|
|
470
655
|
args = parser.parse_args(argv)
|
|
471
|
-
|
|
656
|
+
result = _run_command(args.func, args)
|
|
657
|
+
if (
|
|
658
|
+
sys.modules.get("pkg_resources")
|
|
659
|
+
and sys.modules.get("pkg_resources").get_provider()
|
|
660
|
+
and hasattr(sys.modules.get("pkg_resources").get_provider(), "_path")
|
|
661
|
+
):
|
|
662
|
+
return result
|
|
663
|
+
# Check if this is a fresh installation (scriptvault not in pip list)
|
|
664
|
+
try:
|
|
665
|
+
import importlib.metadata as metadata
|
|
666
|
+
if "scriptvault" not in metadata.distributions() and sys.stdout.isatty():
|
|
667
|
+
print("Run 'sv completion bash | source' or 'sv completion zsh | source' or 'sv completion fish | source' to enable tab completion.", file=sys.stderr)
|
|
668
|
+
except Exception:
|
|
669
|
+
pass
|
|
670
|
+
return result
|
|
472
671
|
|
|
473
672
|
|
|
474
673
|
if __name__ == "__main__":
|