File tree Expand file tree Collapse file tree
implement-shell-tools/cat Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,23 +29,28 @@ const pathsArray = argumentArray;
2929let count = 1 ;
3030
3131for ( let path of pathsArray ) {
32- const context = await fs . readFile ( path , "utf-8" ) ;
33- const lines = context . trimEnd ( ) . split ( "\n" ) ;
34- if ( options . nonBlank ) {
35- lines . forEach ( ( line ) => {
36- if ( line . length != 0 ) {
32+ try {
33+ const context = await fs . readFile ( path , "utf-8" ) ;
34+ const lines = context . trimEnd ( ) . split ( "\n" ) ;
35+ if ( options . nonBlank ) {
36+ lines . forEach ( ( line ) => {
37+ if ( line . trim ( ) . length != 0 ) {
38+ console . log ( ` ${ count } ${ line } ` ) ;
39+ count ++ ;
40+ } else {
41+ console . log ( line ) ;
42+ }
43+ } ) ;
44+ } else if ( options . line ) {
45+ lines . forEach ( ( line ) => {
3746 console . log ( ` ${ count } ${ line } ` ) ;
3847 count ++ ;
39- } else {
40- console . log ( line ) ;
41- }
42- } ) ;
43- } else if ( options . line ) {
44- lines . forEach ( ( line ) => {
45- console . log ( ` ${ count } ${ line } ` ) ;
46- count ++ ;
47- } ) ;
48- } else {
49- console . log ( context . trimEnd ( ) ) ;
48+ } ) ;
49+ } else {
50+ console . log ( context . trimEnd ( ) ) ;
51+ }
52+ } catch ( error ) {
53+ console . error ( error . message ) ;
54+ process . exitCode = 1 ;
5055 }
5156}
You can’t perform that action at this time.
0 commit comments