@@ -19,18 +19,28 @@ class Invoker {
1919 this . showVersion ( )
2020 process . exit ( 0 )
2121 }
22+ if ( files . length === 0 && ! this . options . stdin ) {
23+ // nothing to do...
24+ this . showHelp ( )
25+ process . exit ( 0 )
26+ }
2227 Invoker . prepareProcessor ( args , asciidoctor )
2328 const options = this . options . options
2429 const failureLevel = options [ 'failure_level' ]
25- if ( this . options . stdin ) {
26- await Invoker . convertFromStdin ( options , args )
27- Invoker . exit ( failureLevel )
28- } else if ( files && files . length > 0 ) {
29- Invoker . processFiles ( files , verbose , args [ 'timings' ] , options )
30+ try {
31+ if ( this . options . stdin ) {
32+ await Invoker . convertFromStdin ( options , args )
33+ } else if ( files && files . length > 0 ) {
34+ Invoker . convertFiles ( files , verbose , args [ 'timings' ] , options )
35+ }
3036 Invoker . exit ( failureLevel )
31- } else {
32- this . showHelp ( )
33- process . exit ( 0 )
37+ } catch ( e ) {
38+ if ( e && e . name === 'NotImplementedError' && e . message === `asciidoctor: FAILED: missing converter for backend '${ options . backend } '. Processing aborted.` ) {
39+ console . error ( `> Error: missing converter for backend '${ options . backend } '. Processing aborted.` )
40+ console . error ( `> You might want to require a Node.js package with --require option to support this backend.` )
41+ process . exit ( 1 )
42+ }
43+ throw e
3444 }
3545 }
3646
@@ -69,42 +79,25 @@ CLI version ${pkg.version}`
6979 if ( args [ 'timings' ] ) {
7080 const timings = asciidoctor . Timings . create ( )
7181 const instanceOptions = Object . assign ( { } , options , { timings } )
72- Invoker . convert ( asciidoctor . convert , data , instanceOptions )
82+ asciidoctor . convert ( data , instanceOptions )
7383 timings . printReport ( process . stderr , '-' )
7484 } else {
75- Invoker . convert ( asciidoctor . convert , data , options )
76- }
77- }
78-
79- static convert ( processorFn , input , options ) {
80- try {
81- processorFn . apply ( asciidoctor , [ input , options ] )
82- } catch ( e ) {
83- if ( e && e . name === 'NotImplementedError' && e . message === `asciidoctor: FAILED: missing converter for backend '${ options . backend } '. Processing aborted.` ) {
84- console . error ( `> Error: missing converter for backend '${ options . backend } '. Processing aborted.` )
85- console . error ( `> You might want to require a Node.js package with --require option to support this backend.` )
86- process . exit ( 1 )
87- }
88- throw e
85+ asciidoctor . convert ( data , options )
8986 }
9087 }
9188
92- static convertFile ( file , options ) {
93- Invoker . convert ( asciidoctor . convertFile , file , options )
94- }
95-
96- static processFiles ( files , verbose , timings , options ) {
89+ static convertFiles ( files , verbose , timings , options ) {
9790 files . forEach ( ( file ) => {
9891 if ( verbose ) {
9992 console . log ( `converting file ${ file } ` )
10093 }
10194 if ( timings ) {
10295 const timings = asciidoctor . Timings . create ( )
10396 const instanceOptions = Object . assign ( { } , options , { timings } )
104- Invoker . convertFile ( file , instanceOptions )
97+ asciidoctor . convertFile ( file , instanceOptions )
10598 timings . printReport ( process . stderr , file )
10699 } else {
107- Invoker . convertFile ( file , options )
100+ asciidoctor . convertFile ( file , options )
108101 }
109102 } )
110103 }
0 commit comments