@@ -96,6 +96,7 @@ function printHelp() {
9696 console . log ( `Coder Studio CLI
9797
9898Usage:
99+ coder-studio help [command]
99100 coder-studio start [--host 127.0.0.1] [--port 41033] [--foreground] [--json]
100101 coder-studio stop [--json]
101102 coder-studio restart [--json]
@@ -119,6 +120,7 @@ Exit Codes:
119120 2 usage or argument error
120121
121122Examples:
123+ coder-studio help start
122124 coder-studio start
123125 coder-studio config show --json
124126 coder-studio config root set /srv/coder-studio/workspaces
@@ -128,6 +130,123 @@ Run \`coder-studio config --help\` or \`coder-studio auth --help\` for detailed
128130` ) ;
129131}
130132
133+ function printStartHelp ( ) {
134+ console . log ( `coder-studio start
135+
136+ Usage:
137+ coder-studio start [--host <host>] [--port <port>] [--foreground] [--json]
138+
139+ Options:
140+ --host <host> override configured host for this invocation
141+ --port <port> override configured port for this invocation
142+ --foreground keep the runtime in the foreground
143+ --json machine-readable output
144+
145+ Examples:
146+ coder-studio start
147+ coder-studio start --foreground
148+ coder-studio start --port 42033 --json
149+ ` ) ;
150+ }
151+
152+ function printStopHelp ( ) {
153+ console . log ( `coder-studio stop
154+
155+ Usage:
156+ coder-studio stop [--json]
157+
158+ Options:
159+ --json machine-readable output
160+
161+ Examples:
162+ coder-studio stop
163+ coder-studio stop --json
164+ ` ) ;
165+ }
166+
167+ function printRestartHelp ( ) {
168+ console . log ( `coder-studio restart
169+
170+ Usage:
171+ coder-studio restart [--json]
172+
173+ Options:
174+ --json machine-readable output
175+
176+ Examples:
177+ coder-studio restart
178+ coder-studio restart --json
179+ ` ) ;
180+ }
181+
182+ function printStatusHelp ( ) {
183+ console . log ( `coder-studio status
184+
185+ Usage:
186+ coder-studio status [--host <host>] [--port <port>] [--json]
187+
188+ Options:
189+ --host <host> override configured host for this invocation
190+ --port <port> override configured port for this invocation
191+ --json machine-readable output
192+
193+ Examples:
194+ coder-studio status
195+ coder-studio status --json
196+ ` ) ;
197+ }
198+
199+ function printLogsHelp ( ) {
200+ console . log ( `coder-studio logs
201+
202+ Usage:
203+ coder-studio logs [-f] [-n <lines>]
204+
205+ Options:
206+ -f, --follow follow the runtime log
207+ -n, --lines <n> read the last <n> lines
208+
209+ Examples:
210+ coder-studio logs
211+ coder-studio logs -n 200
212+ coder-studio logs -f
213+ ` ) ;
214+ }
215+
216+ function printOpenHelp ( ) {
217+ console . log ( `coder-studio open
218+
219+ Usage:
220+ coder-studio open [--host <host>] [--port <port>] [--json]
221+
222+ Options:
223+ --host <host> override configured host for this invocation
224+ --port <port> override configured port for this invocation
225+ --json machine-readable output
226+
227+ Examples:
228+ coder-studio open
229+ coder-studio open --json
230+ ` ) ;
231+ }
232+
233+ function printDoctorHelp ( ) {
234+ console . log ( `coder-studio doctor
235+
236+ Usage:
237+ coder-studio doctor [--host <host>] [--port <port>] [--json]
238+
239+ Options:
240+ --host <host> override configured host for this invocation
241+ --port <port> override configured port for this invocation
242+ --json machine-readable output
243+
244+ Examples:
245+ coder-studio doctor
246+ coder-studio doctor --json
247+ ` ) ;
248+ }
249+
131250function printConfigHelp ( ) {
132251 console . log ( `coder-studio config
133252
@@ -172,6 +291,46 @@ Examples:
172291` ) ;
173292}
174293
294+ function printHelpTopic ( topic ) {
295+ switch ( topic ) {
296+ case undefined :
297+ case null :
298+ case '' :
299+ case 'main' :
300+ printHelp ( ) ;
301+ return EXIT_SUCCESS ;
302+ case 'start' :
303+ printStartHelp ( ) ;
304+ return EXIT_SUCCESS ;
305+ case 'stop' :
306+ printStopHelp ( ) ;
307+ return EXIT_SUCCESS ;
308+ case 'restart' :
309+ printRestartHelp ( ) ;
310+ return EXIT_SUCCESS ;
311+ case 'status' :
312+ printStatusHelp ( ) ;
313+ return EXIT_SUCCESS ;
314+ case 'logs' :
315+ printLogsHelp ( ) ;
316+ return EXIT_SUCCESS ;
317+ case 'open' :
318+ printOpenHelp ( ) ;
319+ return EXIT_SUCCESS ;
320+ case 'doctor' :
321+ printDoctorHelp ( ) ;
322+ return EXIT_SUCCESS ;
323+ case 'config' :
324+ printConfigHelp ( ) ;
325+ return EXIT_SUCCESS ;
326+ case 'auth' :
327+ printAuthHelp ( ) ;
328+ return EXIT_SUCCESS ;
329+ default :
330+ throw usageError ( `unsupported help topic: ${ topic } ` , 'main' ) ;
331+ }
332+ }
333+
175334function printStatus ( status ) {
176335 console . log ( `status: ${ status . status } ` ) ;
177336 console . log ( `managed: ${ status . managed ? 'yes' : 'no' } ` ) ;
@@ -734,17 +893,20 @@ function printCliError(error, flags) {
734893export async function runCli ( argv = process . argv . slice ( 2 ) ) {
735894 const { command, flags, positionals } = parseArgv ( argv ) ;
736895
737- if ( command === '--version' || command === '-v' || flags . version ) {
738- console . log ( await readPackageVersion ( ) ) ;
739- return EXIT_SUCCESS ;
740- }
896+ try {
897+ if ( command === '--version' || command === '-v' || flags . version ) {
898+ console . log ( await readPackageVersion ( ) ) ;
899+ return EXIT_SUCCESS ;
900+ }
741901
742- if ( command === 'help' || flags . help && ! [ 'config' , 'auth' ] . includes ( command ) ) {
743- printHelp ( ) ;
744- return EXIT_SUCCESS ;
745- }
902+ if ( command === 'help' ) {
903+ return printHelpTopic ( positionals [ 0 ] ) ;
904+ }
905+
906+ if ( flags . help ) {
907+ return printHelpTopic ( command ) ;
908+ }
746909
747- try {
748910 if ( command === 'config' ) {
749911 const context = await resolveCommandContext ( flags ) ;
750912 return await handleConfigCommand ( positionals , flags , context ) ;
0 commit comments