Skip to content

Commit c49f53c

Browse files
committed
feat: Add specify exit code
1 parent 2ed2ebe commit c49f53c

File tree

3 files changed

+72
-21
lines changed

3 files changed

+72
-21
lines changed

docs/content/Development-API/_index.en.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,31 @@ Report error/warning depends on strict flag.
900900

901901
See option [--strict](https://emacs-eask.github.io/Getting-Started/Commands-and-options/#---strict).
902902

903+
# 🚩 Exit Code
904+
905+
## 🔍 Variable: eask--exit-code
906+
907+
Exit code specification.
908+
909+
## 🔍 Function: eask-exit-code (&optional `key`)
910+
911+
Return the exit code by the key symbol in the variable `eask--exit-code`.
912+
913+
```elisp
914+
(eask-exit-code 'misuse) ; by symbol
915+
```
916+
917+
## 🔍 Function: eask--exit (&optional `exit-code` &rest `_`)
918+
919+
Send exit code.
920+
921+
This will kill Emacs process.
922+
923+
```elisp
924+
(eask--exit 2) ; by number
925+
(eask--exit 'misuse) ; by symbol
926+
```
927+
903928
# 🚩 Error Handling
904929

905930
## 🔍 Variable: eask--ignore-error-p
@@ -947,12 +972,6 @@ Prevent Emacs from being killed and inhibit display error/warning messages.
947972
(error "Nothing happens!"))
948973
```
949974

950-
## 🔍 Function: eask--exit (&optional `exit-code` &rest `_`)
951-
952-
Send exit code.
953-
954-
This will kill Emacs process.
955-
956975
# 🚩 File
957976

958977
## 🔍 Function: eask-package-files ()

docs/content/Development-API/_index.zh-tw.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,31 @@ cat /.log/messages.log
890890

891891
見選項 [--strict](https://emacs-eask.github.io/Getting-Started/Commands-and-options/#---strict).
892892

893+
# 🚩 退出代碼
894+
895+
## 🔍 變數: eask--exit-code
896+
897+
退出代碼規格。
898+
899+
## 🔍 函式: eask-exit-code (&optional `key`)
900+
901+
以變數 `eask--exit-code` 中的關鍵符號回傳 exit code。
902+
903+
```elisp
904+
(eask-exit-code 'misuse) ; 按符號
905+
```
906+
907+
## 🔍 函式: eask--exit (&optional `exit-code` &rest `_`)
908+
909+
傳送退出代碼。
910+
911+
這會結束 Emacs 程序。
912+
913+
```elisp
914+
(eask--exit 2) ; 按數字
915+
(eask--exit 'misuse) ; 按符號
916+
```
917+
893918
# 🚩 錯誤處理
894919

895920
## 🔍 變數: eask--ignore-error-p
@@ -937,12 +962,6 @@ cat /.log/messages.log
937962
(error "Nothing happens!"))
938963
```
939964

940-
## 🔍 函式: eask--exit (&optional `exit-code` &rest `_`)
941-
942-
傳送退出代碼。
943-
944-
這會結束 Emacs 程序。
945-
946965
# 🚩 文件
947966

948967
## 🔍 函式: eask-package-files ()

lisp/_prepare.el

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,25 @@ For arguments MSG and ARGS, please see function `eask-msg' for the detials."
17211721
Argument ARGS are direct arguments for functions `eask-error' or `eask-warn'."
17221722
(apply (if (eask-strict-p) #'eask-error #'eask-warn) args))
17231723

1724+
;;
1725+
;;; Exit Code
1726+
1727+
(defconst eask--exit-code
1728+
`((success . 0) ; Unused
1729+
(failure . 1) ; Catchall for general errors
1730+
(misuse . 2))
1731+
"Exit code specification.")
1732+
1733+
(defun eask-exit-code (key)
1734+
"Return the exit code by KEY symbol."
1735+
(alist-get key eask--exit-code))
1736+
1737+
(defun eask--exit (&optional exit-code &rest _)
1738+
"Kill Emacs with EXIT-CODE (default 1)."
1739+
(kill-emacs (or (cond ((numberp exit-code) exit-code)
1740+
((symbolp exit-code) (eask-exit-code exit-code)))
1741+
(eask-exit-code 'failure))))
1742+
17241743
;;
17251744
;;; Error Handling
17261745

@@ -1745,10 +1764,6 @@ Argument ARGS are direct arguments for functions `eask-error' or `eask-warn'."
17451764
(declare (indent 0) (debug t))
17461765
`(eask-ignore-errors (eask--silent-error ,@body)))
17471766

1748-
(defun eask--exit (&optional exit-code &rest _)
1749-
"Kill Emacs with EXIT-CODE (default 1)."
1750-
(kill-emacs (or exit-code 1)))
1751-
17521767
(defun eask--trigger-error ()
17531768
"Trigger error event."
17541769
(when (and (not eask--ignore-error-p)
@@ -1887,12 +1902,10 @@ the exit code. The default value `nil' will be replaced by `1'; therefore
18871902
would send exit code of `1'."
18881903
(let* ((command (eask-2str command)) ; convert to string
18891904
(help-file (concat eask-lisp-root "help/" command))
1890-
;; The default exit code is `1' since `eask-help' prints the help
1905+
;; The default exit code is `2' since `eask-help' prints the help
18911906
;; message on user error 99% of the time.
1892-
;;
1893-
;; TODO: Later replace exit code `1' with readable symbol after
1894-
;; the exit code has specified.
1895-
(print-or-exit-code (or print-or-exit-code 1)))
1907+
(print-or-exit-code (or print-or-exit-code
1908+
(eask-exit-code 'misuse))))
18961909
(if (file-exists-p help-file)
18971910
(with-temp-buffer
18981911
(insert-file-contents help-file)

0 commit comments

Comments
 (0)