@@ -75,6 +75,7 @@ await fs.ensureDir("./tmp");
75
75
- [ Permissions] ( #permissions )
76
76
- [ Markdown] ( #markdown )
77
77
- [ Methods] ( #methods )
78
+ - [ Process] ( #process )
78
79
- [ Modules] ( #modules )
79
80
- [ Variables] ( #variables )
80
81
- [ Experimental] ( #experimental )
@@ -269,26 +270,79 @@ Methods and properties of the `Process` class which implements
269
270
270
271
- ` .pid ` : Returns the process id of the executed command.
271
272
273
+ ``` ts
274
+ // Get the process id.
275
+ const child = $ ` echo foo ` ;
276
+ console .log (" pid:" , child .pid );
277
+ await child ;
278
+ ```
279
+
272
280
- ` .noThrow ` : If invoked the command doesn't throw an error if the command
273
281
returns a none-zero exit code.
274
282
283
+ ``` ts
284
+ // Don't throw an error for none-zero exit codes.
285
+ const { status } = await $ ` exit 1 ` .noThrow ;
286
+ ```
287
+
275
288
- ` .statusCode ` : Returns the status code of the executed command and calls
276
289
` .noThrow ` internally to catch the error and return the status code.
277
290
291
+ ``` ts
292
+ // Get only the status code.
293
+ const statusCode: number = await $ ` exit 1 ` .statusCode ;
294
+ ```
295
+
278
296
- ` .stdout ` Returns ` Promise<string> ` and resolves with the stdout output.
279
297
298
+ ``` ts
299
+ // Get only stdout.
300
+ const foo: string = await $ ` echo foo; echo bar >&2 ` .stdout ;
301
+ ```
302
+
280
303
- ` .stderr ` Returns ` Promise<string> ` and resolves with the stderr output.
281
304
282
- - ` .retry(retries: number) ` Retry the command ` n ` times if it fails.
305
+ ``` ts
306
+ // Get only stderr.
307
+ const bar: string = await $ ` echo foo; echo bar >&2 ` .stderr ;
308
+ ```
309
+
310
+ - ` .retry(retries: number | RetryCallback) ` Retry the command ` n ` times if it
311
+ fails.
312
+
313
+ ``` ts
314
+ // Retry the command 3 times.
315
+ await $ ` exit 1 ` .retry (3 );
316
+
317
+ // Retry the command 3 times using a callback handler.
318
+ await $ ` exit 1 ` .retry (({ retries }: ProcessError ) => retries < 3 );
319
+ ```
283
320
284
321
- ` .delay(delay: number) ` Number of milliseconds to delay the retry of a failed
285
322
command. Default: ` 500 `
286
323
324
+ ``` ts
325
+ // Retry the command 3 times but wait 1sec before executing it again.
326
+ await $ ` exit 1 ` .retry (3 ).delay (1000 );
327
+ ```
328
+
287
329
- ` .timeout(timeout: number) ` Throws an error if the command takes longer than
288
330
the provided ` timeout ` in milliseconds.
289
331
332
+ ``` ts
333
+ // Kill the command if it takes longer than one second.
334
+ await $ ` sleep 10 ` .timeout (1000 );
335
+ ```
336
+
290
337
- ` .kill(signal: Deno.Signal) ` Kills the running process.
291
338
339
+ ``` ts
340
+ // Manually kill the command.
341
+ const child = $ ` sleep 10 ` ;
342
+ setTimout (() => child .kill (" SIGINT" ), 100 );
343
+ await child ;
344
+ ```
345
+
292
346
### Modules
293
347
294
348
- ** $.\[ style] :** Cliffy's color module. A chainable wrapper for Deno's
0 commit comments