Skip to content

Commit

Permalink
code: implement verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Mar 28, 2022
1 parent aa537c7 commit 9de0bb4
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 16 deletions.
6 changes: 6 additions & 0 deletions eask
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ yargs
description: 'turn on debug mode',
type: 'boolean',
})
.option('verbose', {
description: 'log level for all messages; 4 means trace most anything, 0 means nothing.',
alias: 'v',
requiresArg: true,
type: 'number',
})
.demandCommand()
.wrap(yargs.terminalWidth())
.help().argv;
44 changes: 41 additions & 3 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@

(defun eask-pkg-init ()
"Package initialization."
(package-initialize)
(package-refresh-contents)
(eask-with-verbosity 1
(package-initialize)
(package-refresh-contents))
(eask--silent
(eask--update-exec-path)
(eask--update-load-path)))
Expand Down Expand Up @@ -105,10 +106,12 @@

;;; Number (with arguments)
(defun eask-depth () (eask--str2num (eask--flag-value "--depth"))) ; --depth is enabled
(defun eask-verbose () (eask--str2num (eask--flag-value "--verbose")))

(defun eask--handle-global-options ()
"Handle global options."
(when (eask-debug-p) (setq debug-on-error t))
(when (eask-verbose) (setq eask-verbosity (eask-verbose)))
(eask--add-proxy "http" (eask-proxy))
(eask--add-proxy "https" (eask-proxy))
(eask--add-proxy "http" (eask-http-proxy))
Expand Down Expand Up @@ -356,11 +359,46 @@ Eask file in the workspace."
(unless eask--ignore-error-p
;; XXX Log out the error explicitly, so the user will know what causes Emacs
;; to crash.
(message "[ERROR] %s" (apply #'format-message args))
(eask-error 0 "%s" (apply #'format-message args))
(add-hook 'eask-after-command-hook #'eask--exit)))

(advice-add 'error :before #'eask--trigger-error)

;;
;;; Verbosity

(defcustom eask-verbosity 3
"Log level for all messages; 4 means trace most anything, 0 means nothing."
:type 'integer
:group 'eask)

(defcustom eask-timestamps t
"Log messages with timestamps."
:type 'boolean
:group 'eask)

(defmacro eask-with-verbosity (level &rest body)
"If LEVEL is above `eask-verbosity'; hide all messages in BODY."
(declare (indent 1) (debug t))
`(if (>= eask-verbosity ,level) ,@body (eask--silent ,@body)))

(defun eask-info (level msg &rest args) (apply #'eask--log level "[INFO]" msg args))
(defun eask-warn (level msg &rest args) (apply #'eask--log level "[WARNING]" msg args))
(defun eask-error (level msg &rest args) (apply #'eask--log level "[ERROR]" msg args))

(defun eask--log (level prefix msg &rest args)
"If LEVEL is at or below `eask-verbosity', log message."
(eask-with-verbosity level
(message "%s" (apply #'eask--format prefix msg args))))

(defun eask--format (prefix format-control &rest format-args)
"Format Eask messages."
(apply #'format
(concat (when eask-timestamps
(concat (format-time-string "%Y-%m-%d %H:%M:%S ") prefix " "))
format-control)
format-args))

;;
;;; File

Expand Down
6 changes: 3 additions & 3 deletions lisp/archives.el
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
(eask-start
(if package-archives
(progn
(message "")
(mapc #'eask--print-archive package-archives))
(message "\n No archive has been selected")))
(mapc #'eask--print-archive package-archives)
(eask-info 3 "(Total of %s archives)" (length package-archives)))
(eask-info 3 "(No archive has been selected)")))

;;; archives.el ends here
2 changes: 1 addition & 1 deletion lisp/autoloads.el
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
(let* ((name (eask-guess-package-name))
(autoloads-file (expand-file-name (concat name "-autoloads.el"))))
(package-generate-autoloads name default-directory)
(message "\nWrite file %s..." autoloads-file)))
(eask-info 3 "Write file %s..." autoloads-file)))

;;; autoloads.el ends here
6 changes: 3 additions & 3 deletions lisp/clean-elc.el
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
(progn
(dolist (elc elcs)
(ignore-errors (delete-file elc))
(message "Deleting %s..." elc))
(message "(Total of %s .elc files deleted)" (length elcs)))
(message "(No .elc file found in workspace)")))
(eask-info 3 "Deleting %s..." elc))
(eask-info 3 "(Total of %s .elc files deleted)" (length elcs)))
(eask-info 3 "(No .elc file found in workspace)")))

;;; clean-elc.el ends here
4 changes: 2 additions & 2 deletions lisp/clean.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(file-name-directory (directory-file-name user-emacs-directory)))))
(ignore-errors (delete-directory target-dir t))
(if eask--first-init-p
(message "(Workspace already cleaned)")
(message "Done (workspace `%s` is cleaned)" target-dir))))
(eask-info 3 "(Workspace already cleaned)")
(eask-info 3 "Done (workspace `%s` is cleaned)" target-dir))))

;;; clean.el ends here
8 changes: 4 additions & 4 deletions lisp/compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
(eask-start
(eask-pkg-init)
(let ((files (or (eask-args) (eask-package-el-files))) compiled)
(dolist (filename files)
(when (eask--byte-compile-file filename)
(push filename compiled)))
(message "\n Total of %s files compiled" (length compiled))))
(eask-with-verbosity 3
(dolist (filename files)
(when (eask--byte-compile-file filename) (push filename compiled))))
(eask-info 3 "(Total of %s files compiled)" (length compiled))))

;;; compile.el ends here
1 change: 1 addition & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function _global_options(argv) {
flags.push(def_flag(argv['no-proxy'], '--no-proxy', argv['no-proxy']));
/* Others */
flags.push(def_flag(argv.debug, '--debug'));
flags.push(def_flag(argv.verbose, '--verbose'));
return flags;
}

Expand Down

0 comments on commit 9de0bb4

Please sign in to comment.