-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdemo.citty.ts
More file actions
197 lines (185 loc) · 4.04 KB
/
demo.citty.ts
File metadata and controls
197 lines (185 loc) · 4.04 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import {
defineCommand,
createMain,
type CommandDef,
type ArgsDef,
} from 'citty';
import tab from '../src/citty';
const main = defineCommand({
meta: {
name: 'vite',
version: '0.0.0',
description: 'Vite CLI',
},
args: {
project: {
type: 'positional',
description: 'Project name',
required: true,
},
config: {
type: 'string',
description: 'Use specified config file',
alias: 'c',
},
mode: {
type: 'string',
description: 'Set env mode',
alias: 'm',
},
logLevel: {
type: 'string',
description: 'info | warn | error | silent',
alias: 'l',
},
},
run: (_ctx) => {},
});
const devCommand = defineCommand({
meta: {
name: 'dev',
description: 'Start dev server',
},
args: {
host: {
type: 'string',
description: 'Specify hostname',
alias: 'H',
},
port: {
type: 'string',
description: 'Specify port',
alias: 'p',
},
verbose: {
type: 'boolean',
description: 'Enable verbose logging',
alias: 'v',
},
quiet: {
type: 'boolean',
description: 'Suppress output',
},
},
run: () => {},
});
const buildCommand = defineCommand({
meta: {
name: 'build',
description: 'Build project',
},
run: () => {},
});
const startCommand = defineCommand({
meta: {
name: 'start',
description: 'Start development server',
},
run: () => {},
});
const copyCommand = defineCommand({
meta: {
name: 'copy',
description: 'Copy files',
},
args: {
source: {
type: 'positional',
description: 'Source file or directory',
required: true,
},
destination: {
type: 'positional',
description: 'Destination file or directory',
required: true,
},
},
run: () => {},
});
const lintCommand = defineCommand({
meta: {
name: 'lint',
description: 'Lint project',
},
args: {
files: {
type: 'positional',
description: 'Files to lint',
required: false,
},
},
run: () => {},
});
devCommand.subCommands = {
build: buildCommand,
start: startCommand,
};
main.subCommands = {
dev: devCommand,
copy: copyCommand,
lint: lintCommand,
} as Record<string, CommandDef<ArgsDef>>;
const completion = await tab(main, {
args: {
project: function (complete) {
complete('my-app', 'My application');
complete('my-lib', 'My library');
complete('my-tool', 'My tool');
},
},
options: {
config: function (this: any, complete) {
complete('vite.config.ts', 'Vite config file');
complete('vite.config.js', 'Vite config file');
},
mode: function (this: any, complete) {
complete('development', 'Development mode');
complete('production', 'Production mode');
},
logLevel: function (this: any, complete) {
complete('info', 'Info level');
complete('warn', 'Warn level');
complete('error', 'Error level');
complete('silent', 'Silent level');
},
},
subCommands: {
copy: {
args: {
source: function (complete) {
complete('src/', 'Source directory');
complete('dist/', 'Distribution directory');
complete('public/', 'Public assets');
},
destination: function (complete) {
complete('build/', 'Build output');
complete('release/', 'Release directory');
complete('backup/', 'Backup location');
},
},
},
lint: {
args: {
files: function (complete) {
complete('main.ts', 'Main file');
complete('index.ts', 'Index file');
},
},
},
dev: {
options: {
port: function (this: any, complete) {
complete('3000', 'Development server port');
complete('8080', 'Alternative port');
},
host: function (this: any, complete) {
complete('localhost', 'Localhost');
complete('0.0.0.0', 'All interfaces');
},
},
},
},
});
void completion;
const cli = createMain(main);
cli();