Skip to content

Commit 8a5aa79

Browse files
committed
Add exit-code param to eask-help
1 parent 01d91dc commit 8a5aa79

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

lisp/_prepare.el

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,18 +1860,33 @@ Arguments FNC and ARGS are used for advice `:around'."
18601860
(eask-msg (ansi-white (buffer-string)))
18611861
(eask-msg (concat "''" (spaces-string max-column) "''"))))
18621862

1863-
(defun eask-help (command)
1864-
"Show COMMAND's help instruction."
1863+
(defun eask-help (command &optional print-or-exit-code)
1864+
"Show COMMAND's help instruction.
1865+
1866+
When the optional variable PRINT-OR-EXIT-CODE is a number, it will exit with
1867+
that code. Set to non-nil would just print the help message without sending
1868+
the exit code. The default value `nil' will be replaced by `1'; therefore
1869+
would send exit code of `1'."
18651870
(let* ((command (eask-2str command)) ; convert to string
1866-
(help-file (concat eask-lisp-root "help/" command)))
1871+
(help-file (concat eask-lisp-root "help/" command))
1872+
;; The default exit code is `1' since `eask-help' prints the help
1873+
;; message on user error 99% of the time.
1874+
;;
1875+
;; TODO: Later replace exit code `1' with readable symbol after
1876+
;; the exit code has specified.
1877+
(print-or-exit-code (or print-or-exit-code 1)))
18671878
(if (file-exists-p help-file)
18681879
(with-temp-buffer
18691880
(insert-file-contents help-file)
18701881
(unless (string-empty-p (buffer-string))
18711882
(let ((buf-str (eask--msg-displayable-kwds (buffer-string))))
18721883
(erase-buffer)
18731884
(insert buf-str))
1874-
(eask--help-display)))
1885+
(eask--help-display))
1886+
;; Exit with code if needed
1887+
(cond ((numberp print-or-exit-code)
1888+
(eask--exit print-or-exit-code))
1889+
(t ))) ; Don't exit with anything else.
18751890
(eask-error "Help manual missing %s" help-file))))
18761891

18771892
;;

lisp/link/add.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
(eask-link-add--create source)
8484
(when (and (zerop (length links)) ; if no link previously,
8585
(= 1 (length (eask-link-list)))) ; and first link created!
86-
(eask-help "link/add/success/pkg")))
86+
(eask-help "link/add/success/pkg" t))) ;; don't error
8787
((ignore-errors (file-exists-p pkg-eask))
8888
(eask-log "💡 Validating package through %s... done!" pkg-eask)
8989
(eask--save-load-eask-file pkg-eask
@@ -113,7 +113,7 @@
113113
(eask-link-add--create source)
114114
(when (and (zerop (length links)) ; if no link previously,
115115
(= 1 (length (eask-link-list)))) ; and first link created!
116-
(eask-help "link/add/success/eask")))
116+
(eask-help "link/add/success/eask" t))) ;; don't error
117117
(eask-error "✗ Error loading Eask-file: %s" pkg-eask)))
118118
(t
119119
(eask-info "(Missing `%s-pkg.el` file in your source folder)" name)

0 commit comments

Comments
 (0)