@gutenye/script.js 2.8.0 → 2.9.1
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.
- package/README.md +0 -21
- package/package.json +1 -1
- package/src/Command.ts +4 -2
- package/src/index.ts +1 -0
- package/src/parseArgv.ts +4 -0
package/README.md
CHANGED
|
@@ -27,8 +27,6 @@ npm install -g @gutenye/script.js
|
|
|
27
27
|
|
|
28
28
|
### 2. Write Your First Script
|
|
29
29
|
|
|
30
|
-
**Via script.js** — globals are set up automatically, no imports needed:
|
|
31
|
-
|
|
32
30
|
```ts
|
|
33
31
|
#!/usr/bin/env script.js
|
|
34
32
|
|
|
@@ -42,25 +40,6 @@ app
|
|
|
42
40
|
});
|
|
43
41
|
```
|
|
44
42
|
|
|
45
|
-
**Via import** — use as a library in any Bun script:
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
#!/usr/bin/env bun
|
|
49
|
-
|
|
50
|
-
import { app, $ } from "@gutenye/script.js";
|
|
51
|
-
|
|
52
|
-
app.meta("hello");
|
|
53
|
-
|
|
54
|
-
app
|
|
55
|
-
.cmd("greetings", "Say hello")
|
|
56
|
-
.add("[...files]", "Files", ["$files"])
|
|
57
|
-
.add((files, ctx) => {
|
|
58
|
-
$`ls -l ${files}`;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
await app.run();
|
|
62
|
-
```
|
|
63
|
-
|
|
64
43
|
### 3. Run the script
|
|
65
44
|
|
|
66
45
|
You can use `<Tab>` to autocomplete arguments or options while using the script.
|
package/package.json
CHANGED
package/src/Command.ts
CHANGED
|
@@ -262,10 +262,12 @@ export class Command {
|
|
|
262
262
|
if (arg.completion.length === 0) continue
|
|
263
263
|
if (arg.completion.some((c) => c.startsWith('$') || /^[<[]/.test(c)))
|
|
264
264
|
continue
|
|
265
|
+
// Extract keys from "key\tdescription" format for validation
|
|
266
|
+
const keys = arg.completion.map((c) => c.split('\t')[0])
|
|
265
267
|
const values = arg.variadic ? value : [value]
|
|
266
268
|
for (const v of values) {
|
|
267
|
-
if (!
|
|
268
|
-
return `Invalid value for ${arg.name}: '${v}' (expected: ${
|
|
269
|
+
if (!keys.includes(v)) {
|
|
270
|
+
return `Invalid value for ${arg.name}: '${v}' (expected: ${keys.join(', ')})`
|
|
269
271
|
}
|
|
270
272
|
}
|
|
271
273
|
}
|
package/src/index.ts
CHANGED
package/src/parseArgv.ts
CHANGED