Skip to content

Commit c9c4cf2

Browse files
committed
code: Add new options, allow-error
1 parent a084782 commit c9c4cf2

4 files changed

Lines changed: 37 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ The project structure are very simple, all we need is to look into 3 places.
202202
1. `eask` file at the root of the project
203203
2. `cmds` folder with all available commands
204204
3. `lisp` folder with all elisp code
205+
- `lisp/extern` is the external modules/packages we used
205206

206207
`eask` is the node entry, and the main yargs definition! `cmds` and `lisp`
207208
folders are command files that correspond to each other.

eask

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ yargs
3737
description: 'report error instead of warnings',
3838
type: 'boolean',
3939
})
40+
.option('allow-error', {
41+
description: 'report error at the very end',
42+
type: 'boolean',
43+
})
4044
.option('timestamps', {
4145
description: 'log with timestamps',
4246
type: 'boolean',

lisp/_prepare.el

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ the `eask-start' execution.")
156156
(defun eask-log-level-p () (eask--flag "--log-level")) ; --log-level
157157
(defun eask-no-log-level-p () (eask--flag "--no-log-level")) ; --no-log-level
158158
(defun eask-no-color-p () (eask--flag "--no-color")) ; --no-color
159+
(defun eask-allow-error-p () (eask--flag "--allow-error")) ; --allow-error
159160

160161
;;; String (with arguments)
161162
(defun eask-proxy () (eask--flag-value "--proxy")) ; --proxy
@@ -212,7 +213,8 @@ other scripts internally. See function `eask-call'.")
212213
"--debug" "--strict"
213214
"--timestamps" "--no-timestamps"
214215
"--log-level" "--no-log-level"
215-
"--no-color"))
216+
"--no-color"
217+
"--allow-error"))
216218
"List of boolean type options")
217219

218220
(defconst eask--option-args
@@ -428,16 +430,28 @@ Eask file in the workspace."
428430

429431
(defun eask--exit (&rest _) "Send exit code." (kill-emacs 1))
430432

431-
(defun eask--trigger-error (&rest args)
432-
"Trigger error."
433+
(defun eask--trigger-error ()
434+
"Trigger error at the right time."
435+
(if (eask-allow-error-p)
436+
(add-hook 'eask-after-command-hook #'eask--exit)
437+
(eask--exit)))
438+
439+
(defun eask--error (fnc &rest args)
440+
"On error."
433441
(unless eask--ignore-error-p
434442
;; XXX Log out the error explicitly, so the user will know what causes Emacs
435443
;; to crash.
436-
(let ((eask-log-level t))
437-
(eask-error "%s" (apply #'format-message args)))
438-
(add-hook 'eask-after-command-hook #'eask--exit)))
444+
(eask-msg "%s" (eask--asni 'error (apply #'format-message args)))
445+
(eask--trigger-error))
446+
(when debug-on-error (apply fnc args)))
447+
448+
(advice-add 'error :around #'eask--error)
439449

440-
(advice-add 'error :before #'eask--trigger-error)
450+
(defun eask--warn (&rest args)
451+
"On warn."
452+
(eask-msg "%s" (eask--asni 'warn (apply #'format-message args))))
453+
454+
(advice-add 'warn :override #'eask--warn)
441455

442456
;;
443457
;;; Verbosity
@@ -498,13 +512,20 @@ and the BODY will be executed silently."
498512
(defun eask-log (msg &rest args) (apply #'eask--msg 'log "[LOG]" msg args))
499513
(defun eask-info (msg &rest args) (apply #'eask--msg 'info "[INFO]" msg args))
500514
(defun eask-warn (msg &rest args) (apply #'eask--msg 'warn "[WARNING]" msg args))
501-
(defun eask-error (msg &rest args) (apply #'eask--msg 'error "[ERROR]" msg args))
515+
(defun eask-error (msg &rest args)
516+
(apply #'eask--msg 'error "[ERROR]" msg args)
517+
(eask--trigger-error))
518+
519+
(defun eask--asni (symbol string)
520+
"Wrap STRING with log SYMBOL."
521+
(let ((ansi-function (cdr (assq symbol eask-level-color))))
522+
(funcall ansi-function string)))
502523

503524
(defun eask--msg (symbol prefix msg &rest args)
504525
"If LEVEL is at or below `eask-verbosity', log message."
505526
(eask-with-verbosity symbol
506-
(let* ((ansi-function (cdr (assq symbol eask-level-color)))
507-
(output (funcall ansi-function (apply #'eask--format prefix msg args))))
527+
(let* ((string (apply #'eask--format prefix msg args))
528+
(output (eask--asni symbol string)))
508529
(message "%s" output))))
509530

510531
(defun eask--format (prefix fmt &rest args)

src/util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function _global_options(argv) {
5959
flags.push(def_flag(argv.development, '--dev'));
6060
flags.push(def_flag(argv.debug, '--debug'));
6161
flags.push(def_flag(argv.strict, '--strict'));
62+
flags.push(def_flag(argv['allow-error'], '--allow-error'));
6263
flags.push(def_flag(argv.timestamps, (argv.timestamps) ? '--timestamps' : '--no-timestamps'));
6364
flags.push(def_flag(argv['log-level'], (argv['log-level']) ? '--log-level' : '--no-log-level'));
6465
flags.push(def_flag(argv['color'], '--no-color'));

0 commit comments

Comments
 (0)