77``` typescript
88import type { ChalkInstance } from " chalk" ;
99import type { Logger } from " ts-log" ;
10- import { LogLevel , Output , Program } from " @libreworks/cli" ;
10+ import { Output , Program } from " @libreworks/cli" ;
1111
1212const sleep = (ms : number ) => new Promise ((r ) => setTimeout (r , ms ));
1313
@@ -19,39 +19,37 @@ async function makeLogEntries(logger: Logger, colors: ChalkInstance) {
1919 }
2020}
2121
22- const output = Output .create ({
23- verbosity: LogLevel .TRACE ,
24- color: true ,
25- });
22+ const output = Output .create ({});
2623
27- const command = new Command (" @libreworks/cli:example-handling-output" )
24+ const program = new Program (" @libreworks/cli:example-handling-output" )
2825 .description (" A test of @libreworks/cli" )
29- .version (" 0.0.0" )
30- .action (async function (options , cmd ) {
31- // Send data as-is to stdout.
32- output .write (" You called the handler!" );
33-
34- // Use the logger, which writes to stderr.
35- output .log .info (" Handler invoked" , { options });
36- output .log .info (` Testing ${output .colors .red (" 123" )} ` );
37-
38- await Promise .all ([
39- // Send logs to stderr at regular intervals.
40- makeLogEntries (output .logger , output .colors ),
41-
42- // Show a loading indicator for 5 seconds.
43- output .spinDuring (sleep (5000 ), " Reticulating Splines" ),
44- ]);
45-
46- output .log .warn (" This is a warning!" );
47-
48- try {
49- throw new Error (" A Big Problem" );
50- } catch (e ) {
51- // Stop the spinner and display the error.
52- output .fail (e );
53- }
54- });
26+ .version (" 0.0.0" );
27+
28+ program .action (async function (options , cmd ) {
29+ // Send data as-is to stdout.
30+ output .write (" You called the handler!" );
31+
32+ // Use the logger, which writes to stderr.
33+ output .log .info (" Handler invoked" , { options });
34+ output .log .info (` Testing ${output .colors .red (" 123" )} ` );
35+
36+ await Promise .all ([
37+ // Send logs to stderr at regular intervals.
38+ makeLogEntries (output .logger , output .colors ),
39+
40+ // Show a loading indicator for 5 seconds.
41+ output .spinDuring (sleep (5000 ), " Reticulating Splines" ),
42+ ]);
43+
44+ output .log .warn (" This is a warning!" );
45+
46+ try {
47+ throw new Error (" A Big Problem" );
48+ } catch (e ) {
49+ // Stop the spinner and display the error.
50+ output .fail (e );
51+ }
52+ });
5553
5654await command .parseAsync ();
5755```
0 commit comments