@gutenye/script.js 2.0.0 → 2.1.0
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/package.json +1 -1
- package/src/Command.ts +14 -0
- package/src/ake/README.md +20 -13
package/package.json
CHANGED
package/src/Command.ts
CHANGED
|
@@ -210,6 +210,7 @@ export class Command {
|
|
|
210
210
|
context: Context,
|
|
211
211
|
) {
|
|
212
212
|
const error =
|
|
213
|
+
Command.#validateRequired(command, positionals) ??
|
|
213
214
|
Command.#validateOptions(command, options) ??
|
|
214
215
|
Command.#validateChoices(command, positionals)
|
|
215
216
|
if (error) {
|
|
@@ -229,6 +230,19 @@ export class Command {
|
|
|
229
230
|
return this.arguments.map(String).join(' ')
|
|
230
231
|
}
|
|
231
232
|
|
|
233
|
+
static #validateRequired(
|
|
234
|
+
command: Command,
|
|
235
|
+
positionals: any[],
|
|
236
|
+
): string | null {
|
|
237
|
+
for (let i = 0; i < command.arguments.length; i++) {
|
|
238
|
+
const arg = command.arguments[i]
|
|
239
|
+
if (arg.required && positionals[i] == null) {
|
|
240
|
+
return `Missing required argument: ${arg.rawName}`
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return null
|
|
244
|
+
}
|
|
245
|
+
|
|
232
246
|
static #validateOptions(
|
|
233
247
|
command: Command,
|
|
234
248
|
options: Record<string, any>,
|
package/src/ake/README.md
CHANGED
|
@@ -4,17 +4,26 @@
|
|
|
4
4
|
|
|
5
5
|
## Start
|
|
6
6
|
|
|
7
|
+
Install it
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install -g @gutenye/script.js
|
|
11
|
+
```
|
|
12
|
+
|
|
7
13
|
1. Create an ake file
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
Create a `./ake` file, and make it executable `chmod +x ake`
|
|
10
16
|
|
|
11
17
|
```ts
|
|
12
|
-
#!/usr/bin/env
|
|
18
|
+
#!/usr/bin/env bun
|
|
13
19
|
|
|
14
|
-
app.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
import { app, $ } from "@gutenye/script.js";
|
|
21
|
+
|
|
22
|
+
app.cmd("greetings").add(() => {
|
|
23
|
+
$`echo greetings`;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await app.run();
|
|
18
27
|
```
|
|
19
28
|
|
|
20
29
|
2. Run it
|
|
@@ -23,7 +32,7 @@ app.cmd('greetings')
|
|
|
23
32
|
ake greetings # find the ake file and runs it
|
|
24
33
|
```
|
|
25
34
|
|
|
26
|
-
3. Supports Shell Completion
|
|
35
|
+
3. Supports Shell Completion
|
|
27
36
|
|
|
28
37
|
- Follow [guide](./completions) to setup
|
|
29
38
|
|
|
@@ -31,14 +40,12 @@ ake greetings # find the ake file and runs it
|
|
|
31
40
|
ake <Tab> # uses ake file's completion
|
|
32
41
|
```
|
|
33
42
|
|
|
34
|
-
## Use a template
|
|
43
|
+
## Use a template / another location
|
|
35
44
|
|
|
36
45
|
Create `~/bin.src/ake/template`
|
|
37
46
|
|
|
38
|
-
## Put ake file in another location
|
|
39
|
-
|
|
40
|
-
Doesn't touch original project files
|
|
41
|
-
|
|
42
47
|
```sh
|
|
43
|
-
akectl init
|
|
48
|
+
akectl init local # create a ake file from template in currenct directory
|
|
49
|
+
akectl init remote # create in ~/bin.src/ake/<dir>, doesn't touch original project files
|
|
50
|
+
akectl edit # Opens a editor to edit the ake file
|
|
44
51
|
```
|