@@ -11,7 +11,7 @@ class Invoker {
1111 this . options = options
1212 }
1313
14- invoke ( ) {
14+ async invoke ( ) {
1515 const processArgs = this . options . argv . slice ( 2 )
1616 const { args } = this . options
1717 const { verbose, version, files } = args
@@ -21,10 +21,13 @@ class Invoker {
2121 }
2222 Invoker . prepareProcessor ( args , asciidoctor )
2323 const options = this . options . options
24+ const failureLevel = options [ 'failure_level' ]
2425 if ( this . options . stdin ) {
25- Invoker . convertFromStdin ( options , args )
26+ await Invoker . convertFromStdin ( options , args )
27+ Invoker . exit ( failureLevel )
2628 } else if ( files && files . length > 0 ) {
2729 Invoker . processFiles ( files , verbose , args [ 'timings' ] , options )
30+ Invoker . exit ( failureLevel )
2831 } else {
2932 this . showHelp ( )
3033 process . exit ( 0 )
@@ -57,17 +60,20 @@ CLI version ${pkg.version}`
5760 console . log ( new Invoker ( ) . version ( ) )
5861 }
5962
60- static convertFromStdin ( options , args ) {
61- stdin . read ( ( data ) => {
62- if ( args [ 'timings' ] ) {
63- const timings = asciidoctor . Timings . create ( )
64- const instanceOptions = Object . assign ( { } , options , { timings } )
65- Invoker . convert ( asciidoctor . convert , data , instanceOptions )
66- timings . printReport ( process . stderr , '-' )
67- } else {
68- Invoker . convert ( asciidoctor . convert , data , options )
69- }
70- } )
63+ static async readFromStdin ( ) {
64+ return stdin . read ( )
65+ }
66+
67+ static async convertFromStdin ( options , args ) {
68+ const data = await Invoker . readFromStdin ( )
69+ if ( args [ 'timings' ] ) {
70+ const timings = asciidoctor . Timings . create ( )
71+ const instanceOptions = Object . assign ( { } , options , { timings } )
72+ Invoker . convert ( asciidoctor . convert , data , instanceOptions )
73+ timings . printReport ( process . stderr , '-' )
74+ } else {
75+ Invoker . convert ( asciidoctor . convert , data , options )
76+ }
7177 }
7278
7379 static convert ( processorFn , input , options ) {
@@ -101,12 +107,6 @@ CLI version ${pkg.version}`
101107 Invoker . convertFile ( file , options )
102108 }
103109 } )
104- let code = 0
105- const logger = asciidoctor . LoggerManager . getLogger ( )
106- if ( logger && typeof logger . getMaxSeverity === 'function' && logger . getMaxSeverity ( ) && logger . getMaxSeverity ( ) >= options [ 'failure_level' ] ) {
107- code = 1
108- }
109- process . exit ( code )
110110 }
111111
112112 static requireLibrary ( requirePath , cwd = process . cwd ( ) ) {
@@ -136,6 +136,15 @@ CLI version ${pkg.version}`
136136 } )
137137 }
138138 }
139+
140+ static exit ( failureLevel ) {
141+ let code = 0
142+ const logger = asciidoctor . LoggerManager . getLogger ( )
143+ if ( logger && typeof logger . getMaxSeverity === 'function' && logger . getMaxSeverity ( ) && logger . getMaxSeverity ( ) >= failureLevel ) {
144+ code = 1
145+ }
146+ process . exit ( code )
147+ }
139148}
140149
141150module . exports = Invoker
0 commit comments