@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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gutenye/script.js",
3
- "version": "2.8.0",
3
+ "version": "2.9.1",
4
4
  "description": "Write shell scripts in JavaScript",
5
5
  "keywords": [
6
6
  "shell",
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 (!arg.completion.includes(v)) {
268
- return `Invalid value for ${arg.name}: '${v}' (expected: ${arg.completion.join(', ')})`
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
@@ -1,3 +1,4 @@
1
1
  export { app, Command } from './Command'
2
2
  export * from './frequent-used-helpers'
3
+ export type { Options } from './parseArgv'
3
4
  export { $ } from './spawn'
package/src/parseArgv.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type { Argument } from './Argument'
2
2
  import type { Option } from './Option'
3
3
 
4
+ export type Options<T = Record<string, any>> = T & {
5
+ $has(key: string): boolean
6
+ }
7
+
4
8
  export function parseArgv(
5
9
  argv: string[],
6
10
  registeredArgs: Argument[],