-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.ts
56 lines (51 loc) · 1.72 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Option, program } from "commander";
import visit from "./lib/visit";
import findStories from "./lib/find-stories";
import getCurl from "./lib/get-curl";
import runStories from "./lib/run-stories";
import { createProject, initProject } from "./lib/project";
import picocolors from "picocolors";
import { version } from "./package.json";
program
.name("fetchbook")
.description("Manage your HTTP requests")
.version(version);
program
.command("init")
.argument(
"[name]",
"name of the project, omit it to initialize an existing one",
)
.description("initialize a fetchbook project")
.action(async (name) => {
await (name ? createProject(name) : initProject());
console.log(picocolors.green("✔"), "Project initialized successfully");
});
program
.command("run")
.description("run your stories")
.argument("[story]", "story file path")
.option("-a, --all", "process all stories in a folder recursively")
.option("-v, --verbose", "verbose")
.option("-d, --dry-run", "dry run")
.option("--demo", "use demo stories")
.action(async (storyFilePath, options) =>
runStories(await findStories(storyFilePath, options), options),
);
program
.command("export")
.description("export your stories to existing formats")
.argument("[story]", "story file path")
.addOption(
new Option("-f, --format <format>", "format")
.choices(["curl"])
.default("curl"),
)
.option("-a, --all", "process all stories in a folder recursively")
.option("--demo", "use demo stories")
.action(async (storyFilePath, options) =>
visit(await findStories(storyFilePath, options), async (story) =>
console.log(await getCurl(new Request(story.url, story.init))),
),
);
program.parse();