@@ -35,6 +35,7 @@ class Alacritty {
3535 this . basePath = path . resolve ( process . env . HOME , ".config/alacritty" ) ;
3636 if ( ! fs . existsSync ( this . basePath ) ) {
3737 log ( error ( `Config directory not found: ${ this . base_path } ` ) ) ;
38+ process . exit ( ) ;
3839 }
3940 this . configFile = `${ this . basePath } /alacritty.yml` ;
4041 if ( ! fs . existsSync ( this . configFile ) ) {
@@ -81,12 +82,14 @@ class Alacritty {
8182 ) ;
8283 } catch ( err ) {
8384 log ( error ( err ) ) ;
85+ process . exit ( ) ;
8486 }
8587 }
8688
8789 resourcePath ( resource ) {
8890 if ( ! ( resource in this . resources ) ) {
8991 log ( error ( `Path for resource "${ resource } " not set` ) ) ;
92+ process . exit ( ) ;
9093 }
9194
9295 resource = this . resources [ resource ] ;
@@ -108,6 +111,7 @@ class Alacritty {
108111 apply ( config ) {
109112 if ( config === null || config . length < 1 ) {
110113 log ( error ( "No options provided" ) ) ;
114+ process . exit ( ) ;
111115 }
112116
113117 const actions = {
@@ -129,12 +133,14 @@ class Alacritty {
129133 } catch ( err ) {
130134 log ( error ( err ) ) ;
131135 errorsFound += 1 ;
136+ process . exit ( ) ;
132137 }
133138 }
134139 }
135140
136141 if ( errorsFound > 0 ) {
137142 log ( error ( `\n${ errorsFound } error(s) found` ) ) ;
143+ process . exit ( ) ;
138144 }
139145 }
140146
@@ -143,13 +149,16 @@ class Alacritty {
143149 const themeFile = `${ themesDirectory } /${ theme } .yaml` ;
144150 if ( ! fs . existsSync ( themeFile ) ) {
145151 log ( error ( `Theme "${ theme } " not found` ) ) ;
152+ process . exit ( ) ;
146153 }
147154 const themeYaml = this . load ( themeFile ) ;
148155 if ( themeYaml === null ) {
149156 log ( error ( `File ${ themeFile . name } is empty` ) ) ;
157+ process . exit ( ) ;
150158 }
151159 if ( ! themeYaml [ "colors" ] ) {
152160 log ( error ( `${ themeFile } does not contain color config` ) ) ;
161+ process . exit ( ) ;
153162 }
154163
155164 const expected_colors = [
@@ -187,6 +196,7 @@ class Alacritty {
187196 size = Number ( size ) ;
188197 if ( size <= 0 ) {
189198 log ( error ( "Font size cannot be negative or zero" ) ) ;
199+ process . exit ( ) ;
190200 }
191201
192202 if ( ! ( "font" in this . config ) ) {
@@ -203,6 +213,7 @@ class Alacritty {
203213 opacity = Number ( opacity ) ;
204214 if ( opacity < 0.0 || opacity > 1.0 ) {
205215 log ( error ( "Opacity should be between 0.0 and 1.0" ) ) ;
216+ process . exit ( ) ;
206217 }
207218
208219 this . config [ "background_opacity" ] = opacity ;
@@ -219,15 +230,18 @@ class Alacritty {
219230 let fonts = this . load ( fontsFile ) ;
220231 if ( fonts === null ) {
221232 log ( error ( `File "${ fontsFile } " is empty` ) ) ;
233+ process . exit ( ) ;
222234 }
223235 if ( ! ( "fonts" in fonts ) ) {
224236 log ( error ( `No font config found in "${ fontsFile } "` ) ) ;
237+ process . exit ( ) ;
225238 }
226239
227240 fonts = fonts [ "fonts" ] ;
228241
229242 if ( ! ( font in fonts ) ) {
230243 log ( error ( `Config for font "${ font } " not found` ) ) ;
244+ process . exit ( ) ;
231245 }
232246
233247 const fontTypes = [ "normal" , "bold" , "italic" ] ;
@@ -242,11 +256,12 @@ class Alacritty {
242256
243257 if ( ! ( fonts [ font ] instanceof Object ) ) {
244258 log ( error ( `Font "${ font } " has wrong format` ) ) ;
259+ process . exit ( ) ;
245260 }
246261
247262 for ( let t in fontTypes ) {
248263 if ( ! ( t in Object . keys ( fonts ) ) ) {
249- log ( warning ( `Font "${ font } " does not have "${ t } " property` ) ) ;
264+ log ( error ( `Font "${ font } " does not have "${ t } " property` ) ) ;
250265 }
251266 if ( ! ( t in this . config [ "font" ] ) ) {
252267 this . config [ "font" ] [ fontTypes [ t ] ] = { family : "tmp" } ;
@@ -260,6 +275,17 @@ class Alacritty {
260275 if ( Object . keys ( padding ) . length != 2 ) {
261276 log ( error ( "Padding should only have an x and y value" ) ) ;
262277 }
278+
279+ if ( ! padding . x || ! padding . y ) {
280+ log ( error ( 'Missing "Y" value of padding' ) ) ;
281+ process . exit ( ) ;
282+ }
283+
284+ if ( Math . sign ( padding . x ) === - 1 || Math . sign ( padding . y ) === - 1 ) {
285+ log ( error ( 'The "X" or "Y" values of padding cannot be negative' ) ) ;
286+ process . exit ( ) ;
287+ }
288+
263289 const { x, y } = padding ;
264290 if ( ! ( "window" in this . config ) ) {
265291 this . config [ "window" ] = { } ;
@@ -277,8 +303,19 @@ class Alacritty {
277303
278304 changeFontOffset ( offset ) {
279305 if ( Object . keys ( offset ) . length != 2 ) {
280- log ( error ( "Wrong offset config, should be [x, y]" ) ) ;
306+ log ( error ( "Offset should only have an x and y value" ) ) ;
307+ }
308+
309+ if ( ! offset . x || ! offset . y ) {
310+ log ( error ( 'Missing "Y" value of offset' ) ) ;
311+ process . exit ( ) ;
281312 }
313+
314+ if ( Math . sign ( offset . x ) === - 1 || Math . sign ( offset . y ) === - 1 ) {
315+ log ( error ( 'The "X" or "Y" values of offset cannot be negative' ) ) ;
316+ process . exit ( ) ;
317+ }
318+
282319 const { x, y } = offset ;
283320 if ( ! ( "font" in this . config ) ) {
284321 this . config [ "font" ] = { } ;
@@ -305,6 +342,7 @@ class Alacritty {
305342 } else {
306343 if ( ! ( toBeListed in options ) ) {
307344 log ( error ( `Cannot list ${ toBeListed } , unknown option` ) ) ;
345+ process . exit ( ) ;
308346 }
309347 options [ toBeListed ] ( ) ;
310348 }
@@ -362,7 +400,8 @@ class Alacritty {
362400 const themeFile = `${ themesDir } /${ theme } .yaml` ;
363401
364402 if ( ! fs . existsSync ( themeFile ) ) {
365- log ( error ( `Failed printing "${ theme } " theme, "${ theme_file } " not found` ) ) ;
403+ log ( error ( `Failed printing "${ theme } " theme, "${ themeFile } " not found` ) ) ;
404+ process . exit ( ) ;
366405 }
367406 log ( chalk . blue ( themeFile ) ) ;
368407 log ( yaml . stringify ( this . load ( themeFile ) ) ) ;
@@ -378,12 +417,10 @@ class Alacritty {
378417 toBePrinted . append ( "config" ) ;
379418 }
380419
381- for ( let param in toBePrinted ) {
382- if ( param in options ) {
383- this . printTheme ( param ) ;
384- } else {
385- options [ toBePrinted ] ( ) ;
386- }
420+ if ( toBePrinted in options ) {
421+ options [ toBePrinted ] ( ) ;
422+ } else {
423+ this . printTheme ( toBePrinted ) ;
387424 }
388425 }
389426}
0 commit comments