-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflags.ts
113 lines (102 loc) · 2.97 KB
/
flags.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { parse } from "./lib/degit.ts";
import { flag, flags, z } from "./zcli.ts";
export const fields = flag({
short: "The fields to include in the response.",
aliases: ["F"],
}).array(z.string()).optional();
/**
* Flags that are used for pagination in `list` commands.
*/
export const paginator = flags({
limit: flag({
short: "The number of items to return in the next page.",
}).onumber(),
after: flag({ short: "The cursor to fetch the next results from." })
.ostring(),
orderBy: flag({ short: "The field to order items by." }).enum([
"dtCreated",
]).optional(),
asc: flag({ short: "Whether to order items ascending." }).oboolean(),
desc: flag({ short: "Whether to order items descending." }).oboolean(),
fields,
});
/**
* Degit flags that are used for project scaffolding in `init` commands.
*/
export const degit = flags({
template: flag({
aliases: ["t"],
short: "A template to use when creating the app",
long: `
A template to use when creating the app. This can be a URL
to a git repository or a shorthand template name.
These templates are equivalent:
\`\`\`
user/repo
github:user/repo
[email protected]:user/repo
https://github.com/user/repo
\`\`\`
Download from GitLab:
\`\`\`
gitlab:user/repo
[email protected]:user/repo
https://gitlab.com/user/repo
\`\`\`
Download from Bitbucket
\`\`\`
bitbucket:user/repo
[email protected]:user/repo
https://bitbucket.org/user/repo
\`\`\`
Specify a tag or branch:
\`\`\`
user/repo#dev # branch
user/repo#v1.2.3 # release tag
user/repo#1234abcd # commit hash
\`\`\`
`,
}).ostring().transform((value) => {
if (!value) {
return parse("Paperspace/app-template");
}
return parse(value);
}).superRefine(
(template, ctx) => {
if (!template) {
return true;
}
if (!template.owner) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Missing template owner.",
});
return false;
} else if (!template.repo) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Missing template repo.",
});
return false;
} else if (!template.host) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
"Invalid template host. Must be one of: github, bitbucket, gitlab.",
});
return false;
}
return true;
},
),
mode: flag({
aliases: ["m"],
short: "The mode to use when creating the app: 'git' or 'tar'.",
long: `
The mode to use when creating the app. This can be either "git" or
"tar". If "git" is specified, the template will be downloaded as a
tarball. Note that "git" clones over SSH, so you must have a valid
SSH key configured with GitHub, Bitbucket, or GitLab.
`,
}).enum(["git", "tar"]).default("tar"),
});