Skip to content

Commit d02a7b3

Browse files
committed
docs: multi-file playground
Signed-off-by: Michael Molisani <[email protected]>
1 parent 47b47c5 commit d02a7b3

31 files changed

+919
-852
lines changed

docs/docs/features/argument-parsing/examples/array-argument.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
--help
2+
a b c
3+
/// impl.ts
4+
import type { CommandContext } from "@stricli/core";
5+
6+
export default async function(this: CommandContext, _: {}, ...paths: string[]) {
7+
this.process.stdout.write(`Deleting files at ${paths.join(", ")}`);
8+
}
9+
/// spec.ts
110
import { buildCommand, type CommandContext } from "@stricli/core";
211

3-
export const root = buildCommand({
4-
func(this: CommandContext, _: {}, ...paths: string[]) {
5-
this.process.stdout.write(`Deleting files at ${paths.join(", ")}`);
6-
},
12+
export default buildCommand({
13+
loader: () => import("./impl"),
714
parameters: {
815
positional: {
916
kind: "array",
@@ -17,3 +24,7 @@ export const root = buildCommand({
1724
brief: "Example for live playground with homogenous positional parameters",
1825
},
1926
});
27+
/// !app.ts
28+
import { buildApplication } from "@stricli/core";
29+
import root from "./spec.ts";
30+
export default buildApplication(root, { name: "run" });

docs/docs/features/argument-parsing/examples/boolean-flag.txt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
import { buildCommand, type CommandContext } from "@stricli/core";
1+
--help
2+
--noQuiet
3+
/// impl.ts
4+
import type { CommandContext } from "@stricli/core";
25

3-
interface Flags {
6+
type Flags = {
47
quiet: boolean;
8+
};
9+
10+
export default async function(this: CommandContext, { quiet }: Flags) {
11+
this.process.stdout.write(quiet ? "LOUD LOGGING" : "quiet logging");
512
}
13+
/// spec.ts
14+
import { buildCommand } from "@stricli/core";
615

7-
export const root = buildCommand({
8-
func(this: CommandContext, { quiet }: Flags) {
9-
this.process.stdout.write(quiet ? "LOUD LOGGING" : "quiet logging");
10-
},
16+
export default buildCommand({
17+
loader: () => import("./impl"),
1118
parameters: {
1219
flags: {
1320
quiet: {
@@ -25,3 +32,7 @@ export const root = buildCommand({
2532
],
2633
},
2734
});
35+
/// !app.ts
36+
import { buildApplication } from "@stricli/core";
37+
import root from "./spec.ts";
38+
export default buildApplication(root, { name: "run" });

docs/docs/features/argument-parsing/examples/bounded-array-argument.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
import { buildCommand, numberParser, type CommandContext } from "@stricli/core";
1+
--help
2+
1
3+
1 2
4+
1 2 3
5+
/// impl.ts
6+
import type { CommandContext } from "@stricli/core";
27

3-
export const root = buildCommand({
4-
func(this: CommandContext, _: {}, ...ids: number[]) {
5-
this.process.stdout.write(`Grouping users with IDs: ${ids.join(", ")}`);
6-
},
8+
export default async function(this: CommandContext, _: {}, ...ids: number[]) {
9+
this.process.stdout.write(`Grouping users with IDs: ${ids.join(", ")}`);
10+
}
11+
/// spec.ts
12+
import { buildCommand, numberParser } from "@stricli/core";
13+
14+
export default buildCommand({
15+
loader: () => import("./impl"),
716
parameters: {
817
positional: {
918
kind: "array",
@@ -19,3 +28,7 @@ export const root = buildCommand({
1928
brief: "Example for live playground with bounded positional parameters",
2029
},
2130
});
31+
/// !app.ts
32+
import { buildApplication } from "@stricli/core";
33+
import root from "./spec.ts";
34+
export default buildApplication(root, { name: "run" });

docs/docs/features/argument-parsing/examples/counter-flag.txt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
import { buildCommand, type CommandContext } from "@stricli/core";
1+
--help
2+
-vv -v
3+
/// impl.ts
4+
import type { CommandContext } from "@stricli/core";
5+
6+
type Flags = {
7+
verbose: number;
8+
};
9+
10+
export default async function(this: CommandContext, { verbose }: Flags) {
11+
this.process.stdout.write(`Logging with verbosity level ${verbose}`);
12+
}
13+
/// spec.ts
14+
import { buildCommand } from "@stricli/core";
215

316
interface Flags {
417
verbose: number;
518
}
619

7-
export const root = buildCommand({
8-
func(this: CommandContext, { verbose }: Flags) {
9-
this.process.stdout.write(`Logging with verbosity level ${verbose}`);
10-
},
20+
export default buildCommand({
21+
loader: () => import("./impl"),
1122
parameters: {
1223
flags: {
1324
verbose: {
@@ -29,3 +40,7 @@ export const root = buildCommand({
2940
],
3041
},
3142
});
43+
/// !app.ts
44+
import { buildApplication } from "@stricli/core";
45+
import root from "./spec.ts";
46+
export default buildApplication(root, { name: "run" });

docs/docs/features/argument-parsing/examples/default-flag.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import { buildCommand, type CommandContext } from "@stricli/core";
1+
--help
2+
/// impl.ts
3+
import type { CommandContext } from "@stricli/core";
24

3-
interface Flags {
5+
type Flags = {
46
lineEnding: "lf" | "crlf";
7+
};
8+
9+
export default async function(this: CommandContext, { lineEnding }: Flags) {
10+
this.process.stdout.write(`Switched line ending to ${lineEnding}`);
511
}
12+
/// spec.ts
13+
import { buildCommand } from "@stricli/core";
614

7-
export const root = buildCommand({
8-
func(this: CommandContext, { lineEnding }: Flags) {
9-
this.process.stdout.write(`Switched line ending to ${lineEnding}`);
10-
},
15+
export default buildCommand({
16+
loader: () => import("./impl"),
1117
parameters: {
1218
flags: {
1319
lineEnding: {
@@ -22,3 +28,7 @@ export const root = buildCommand({
2228
brief: "Example for live playground with flag configured with default value",
2329
},
2430
});
31+
/// !app.ts
32+
import { buildApplication } from "@stricli/core";
33+
import root from "./spec.ts";
34+
export default buildApplication(root, { name: "run" });

docs/docs/features/argument-parsing/examples/default-tuple-argument.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { buildCommand, type CommandContext } from "@stricli/core";
1+
--help
22

3-
export const root = buildCommand({
4-
func(this: CommandContext, _: {}, outputPath: string) {
5-
this.process.stdout.write(`Printing file to ${outputPath}`);
6-
},
3+
/// impl.ts
4+
import type { CommandContext } from "@stricli/core";
5+
6+
export default async function(this: CommandContext, _: {}, outputPath: string) {
7+
this.process.stdout.write(`Printing file to ${outputPath}`);
8+
}
9+
/// spec.ts
10+
import { buildCommand } from "@stricli/core";
11+
12+
export default buildCommand({
13+
loader: () => import("./impl"),
714
parameters: {
815
positional: {
916
kind: "tuple",
@@ -20,3 +27,7 @@ export const root = buildCommand({
2027
brief: "Example for live playground with positional parameter configured with default value",
2128
},
2229
});
30+
/// !app.ts
31+
import { buildApplication } from "@stricli/core";
32+
import root from "./spec.ts";
33+
export default buildApplication(root, { name: "run" });

docs/docs/features/argument-parsing/examples/enum-flag.txt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
import { buildCommand, type CommandContext } from "@stricli/core";
1+
--help
2+
--level warn
3+
/// impl.ts
4+
import type { CommandContext } from "@stricli/core";
25

3-
interface Flags {
6+
type Flags = {
47
level: "info" | "warn" | "error";
8+
};
9+
10+
export default async function(this: CommandContext, { level }: Flags) {
11+
this.process.stdout.write(`Set logging level to ${level}`);
512
}
13+
/// spec.ts
14+
import { buildCommand } from "@stricli/core";
615

7-
export const root = buildCommand({
8-
func(this: CommandContext, { level }: Flags) {
9-
this.process.stdout.write(`Set logging level to ${level}`);
10-
},
16+
export default buildCommand({
17+
loader: () => import("./impl"),
1118
parameters: {
1219
flags: {
1320
level: {
@@ -24,3 +31,7 @@ export const root = buildCommand({
2431
brief: "Example for live playground with enum flag"
2532
},
2633
});
34+
/// !app.ts
35+
import { buildApplication } from "@stricli/core";
36+
import root from "./spec.ts";
37+
export default buildApplication(root, { name: "run" });

docs/docs/features/argument-parsing/examples/hidden-flag.txt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
import { buildCommand, type CommandContext } from "@stricli/core";
1+
--help
2+
/// impl.ts
3+
import type { CommandContext } from "@stricli/core";
24

3-
interface Flags {
5+
type Flags = {
46
visible?: boolean;
57
hidden?: boolean;
8+
};
9+
10+
export default async function(this: CommandContext, { visible, hidden }: Flags) {
11+
this.process.stdout.write(visible ? "Visible flag active" : "Visible flag inactive");
12+
if (hidden) {
13+
this.process.stdout.write("Hidden flag active");
14+
}
615
}
16+
/// spec.ts
17+
import { buildCommand, type CommandContext } from "@stricli/core";
718

8-
export const root = buildCommand({
9-
func(this: CommandContext, { visible, hidden }: Flags) {
10-
this.process.stdout.write(visible ? "Visible flag active" : "Visible flag inactive");
11-
if (hidden) {
12-
this.process.stdout.write("Hidden flag active");
13-
}
14-
},
19+
export default buildCommand({
20+
loader: () => import("./impl"),
1521
parameters: {
1622
flags: {
1723
visible: {
@@ -31,3 +37,7 @@ export const root = buildCommand({
3137
brief: "Example for live playground with hidden flag"
3238
},
3339
});
40+
/// !app.ts
41+
import { buildApplication } from "@stricli/core";
42+
import root from "./spec.ts";
43+
export default buildApplication(root, { name: "run" });
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--help
2+
3+
--value foobar
4+
--value
5+
/// impl.ts
6+
import type { CommandContext } from "@stricli/core";
7+
8+
type Flags = {
9+
value?: string
10+
};
11+
12+
export default async function(this: CommandContext, flags: Flags) {
13+
this.process.stdout.write(JSON.stringify(flags));
14+
}
15+
/// spec.ts
16+
import { buildCommand, type CommandContext } from "@stricli/core";
17+
18+
export default buildCommand({
19+
loader: () => import("./impl"),
20+
parameters: {
21+
flags: {
22+
value: {
23+
kind: "parsed",
24+
parse: String,
25+
brief: "Exact string value",
26+
optional: true,
27+
inferEmpty: true,
28+
},
29+
},
30+
},
31+
docs: {
32+
brief: "Example for live playground with hidden flag"
33+
},
34+
});
35+
/// !app.ts
36+
import { buildApplication } from "@stricli/core";
37+
import root from "./spec.ts";
38+
export default buildApplication(root, { name: "run" });

docs/docs/features/argument-parsing/examples/optional-flag.txt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
/// impl.ts
2+
import type { CommandContext } from "@stricli/core";
3+
4+
type Flags = {
5+
limit?: number;
6+
};
7+
8+
export default async function(this: CommandContext, { limit }: Flags) {
9+
this.process.stdout.write(limit ? `Set limit to ${limit}` : "No limit");
10+
}
11+
/// spec.ts
112
import { buildCommand, numberParser, type CommandContext } from "@stricli/core";
213

314
interface Flags {
415
limit?: number;
516
}
617

7-
export const root = buildCommand({
8-
func(this: CommandContext, { limit }: Flags) {
9-
this.process.stdout.write(limit ? `Set limit to ${limit}` : "No limit");
10-
},
18+
export default buildCommand({
19+
loader: () => import("./impl"),
1120
parameters: {
1221
flags: {
1322
limit: {
@@ -23,7 +32,10 @@ export const root = buildCommand({
2332
customUsage: [
2433
"",
2534
"--limit 1000",
26-
"--noQuiet",
2735
],
2836
},
2937
});
38+
/// !app.ts
39+
import { buildApplication } from "@stricli/core";
40+
import root from "./spec.ts";
41+
export default buildApplication(root, { name: "run" });

0 commit comments

Comments
 (0)