Skip to content

Commit 5c097d9

Browse files
authored
Set error status when help is printed (#307)
* Fix: typo in some error messages * Fix: minor style changes in lisp/help files Call eask--exit when the message indicates an error * Fix: bad help file link for analyze command * Add exit-code param to eask--exit * Add exit-code param to eask-help * Fix: typo in run script cli doc * Add tests for exit status when displaying help message * Add CI job to test exit status in help commands * Only run Help-Exit job on emacs 30.1 * Fix some CI errors
1 parent 999ce93 commit 5c097d9

File tree

54 files changed

+718
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+718
-82
lines changed

.github/workflows/help_exit.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Help-Exit
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- 'eask'
9+
- '**.yml'
10+
- lisp/**
11+
- cmds/**
12+
- src/**
13+
- test/**
14+
pull_request:
15+
branches:
16+
- master
17+
paths-ignore:
18+
- '**.md'
19+
workflow_dispatch:
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
test:
27+
runs-on: ${{ matrix.os }}
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
os: [ubuntu-latest, macos-latest, windows-latest]
32+
33+
steps:
34+
- uses: jcs090218/setup-emacs@master
35+
with:
36+
version: 30.1
37+
38+
- uses: actions/checkout@v4
39+
40+
- name: Prepare Eask (Unix)
41+
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
42+
run: |
43+
chmod -R 777 ./
44+
.github/scripts/setup-eask
45+
46+
- name: Prepare Eask (Windows)
47+
if: matrix.os == 'windows-latest'
48+
run: .github/scripts/setup-eask.ps1
49+
50+
- name: Testing...
51+
run: |
52+
make command-help-exit

Makefile

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,70 @@ command-config:
3232
command-local:
3333
./test/commands/local/run.sh
3434

35+
# new tests which check missing args not covered by existing tests
36+
command-help-exit: command-bump command-concat command-docs command-eval command-format command-info command-init command-lint command-recipe command-run command-source
37+
3538
command-analyze:
3639
./test/commands/analyze/dsl/run.sh
3740
./test/commands/analyze/metadata/run.sh
41+
./test/commands/analyze/error/run.sh
42+
43+
command-bump:
44+
./test/commands/bump/run.sh
45+
46+
command-compile:
47+
./test/commands/compile/run.sh
48+
49+
command-concat:
50+
./test/commands/concat/run.sh
3851

3952
command-docker:
4053
./test/commands/docker/run.sh
4154

55+
command-docs:
56+
./test/commands/docs/run.sh
57+
58+
command-eval:
59+
./test/commands/eval/run.sh
60+
4261
command-exec:
4362
./test/commands/exec/run.sh
4463

4564
command-emacs:
4665
./test/commands/emacs/run.sh
4766

67+
command-format:
68+
./test/commands/format/run.sh
69+
70+
command-info:
71+
./test/commands/info/run.sh
72+
73+
command-init:
74+
./test/commands/init/run.sh
75+
4876
command-install:
4977
./test/commands/install/run.sh
5078

79+
command-link:
80+
./test/commands/link/run.sh
81+
82+
command-lint:
83+
./test/commands/lint/run.sh
84+
5185
command-outdated-upgrade:
5286
./test/commands/outdated_upgrade/run.sh
5387

88+
command-recipe:
89+
./test/commands/recipe/run.sh
90+
91+
command-run:
92+
./test/commands/run/run.sh
93+
5494
command-search:
5595
./test/commands/search/run.sh
5696

57-
command-link:
58-
./test/commands/link/run.sh
97+
command-source:
98+
./test/commands/source/run.sh
5999

60100
test-ert:
61101
./test/commands/test/ert/run.sh

cmds/run/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const fs = require('fs');
2121
const child_process = require("child_process");
2222

2323
exports.command = ['script [names..]'];
24-
exports.desc = 'Run script nameds [names..]';
24+
exports.desc = 'Run script named [names..]';
2525
exports.builder = yargs => yargs
2626
.positional(
2727
'[names..]', {

lisp/_prepare.el

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,9 @@ Argument ARGS are direct arguments for functions `eask-error' or `eask-warn'."
17301730
(declare (indent 0) (debug t))
17311731
`(eask-ignore-errors (eask--silent-error ,@body)))
17321732

1733-
(defun eask--exit (&rest _) "Send exit code." (kill-emacs 1))
1733+
(defun eask--exit (&optional exit-code &rest _)
1734+
"Kill Emacs with EXIT-CODE (default 1)."
1735+
(kill-emacs (or exit-code 1)))
17341736

17351737
(defun eask--trigger-error ()
17361738
"Trigger error event."
@@ -1861,26 +1863,41 @@ Arguments FNC and ARGS are used for advice `:around'."
18611863
(eask-msg (ansi-white (buffer-string)))
18621864
(eask-msg (concat "''" (spaces-string max-column) "''"))))
18631865

1864-
(defun eask-help (command)
1865-
"Show COMMAND's help instruction."
1866+
(defun eask-help (command &optional print-or-exit-code)
1867+
"Show COMMAND's help instruction.
1868+
1869+
When the optional variable PRINT-OR-EXIT-CODE is a number, it will exit with
1870+
that code. Set to non-nil would just print the help message without sending
1871+
the exit code. The default value `nil' will be replaced by `1'; therefore
1872+
would send exit code of `1'."
18661873
(let* ((command (eask-2str command)) ; convert to string
1867-
(help-file (concat eask-lisp-root "help/" command)))
1874+
(help-file (concat eask-lisp-root "help/" command))
1875+
;; The default exit code is `1' since `eask-help' prints the help
1876+
;; message on user error 99% of the time.
1877+
;;
1878+
;; TODO: Later replace exit code `1' with readable symbol after
1879+
;; the exit code has specified.
1880+
(print-or-exit-code (or print-or-exit-code 1)))
18681881
(if (file-exists-p help-file)
18691882
(with-temp-buffer
18701883
(insert-file-contents help-file)
18711884
(unless (string-empty-p (buffer-string))
18721885
(let ((buf-str (eask--msg-displayable-kwds (buffer-string))))
18731886
(erase-buffer)
18741887
(insert buf-str))
1875-
(eask--help-display)))
1876-
(eask-error "Help manual missig %s" help-file))))
1888+
(eask--help-display))
1889+
;; Exit with code if needed
1890+
(cond ((numberp print-or-exit-code)
1891+
(eask--exit print-or-exit-code))
1892+
(t ))) ; Don't exit with anything else.
1893+
(eask-error "Help manual missing %s" help-file))))
18771894

18781895
;;
18791896
;;; Checker
18801897

18811898
(defun eask--checker-existence ()
18821899
"Return errors if required metadata is missing."
1883-
(unless eask-package (eask-error "Missing metadata package; make sure you have create Eask-file with $ eask init!")))
1900+
(unless eask-package (eask-error "Missing metadata package; make sure you have created an Eask-file with $ eask init!")))
18841901

18851902
(defun eask--check-strings (fmt f p &rest args)
18861903
"Test strings (F and P); then print FMT and ARGS if not equal."

lisp/core/analyze.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,6 @@ Argument LEVEL and MSG are data from the debug log signal."
152152
;; Default, print help!
153153
(t
154154
(eask-info "(No Eask-files have been checked)")
155-
(eask-help "checker/analyze"))))
155+
(eask-help "core/analyze"))))
156156

157157
;;; core/analyze.el ends here

lisp/help/core/analyze

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
2-
💡 You need to specify file(s) you want to Eask checker to check
1+
2+
💡 You need to specify file(s) you want Eask checker to check
33

44
$ eask analyze FILE-1 FILE-2

lisp/help/core/concat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
💡 You would need to specify the [names..] in order to make concatenation!
2+
💡 You need to specify the file [names..] in order to concatenate!
33

44
$ eask concat [names..]

lisp/help/core/docs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
💡 You would need to specify the [names..] in order to build documentation!
2+
💡 You need to specify the file [names..] in order to build documentation!
33

44
$ eask docs [names..]

lisp/help/core/eval

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
💡 You would need to specify the [form] in order to make execution!
2+
💡 You need to specify the [form] to evaluate!
33

44
$ eask eval [form]

lisp/help/core/exec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
💡 You would need to specify the program name in order to make execution!
3-
2+
💡 You need to specify the program name to execute!
3+
44
$ eask exec <program> [options..]

lisp/help/core/info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
💡 You need Eask-file to show information about the config/package, to create one:
2+
💡 You need an Eask-file to show information about the config/package; to create one:
33

44
$ eask init
55

lisp/help/core/install-deps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
💡 You can add dependencies by using specifier [depends-on]
2+
💡 You can add dependencies by using the specifier [depends-on]
33

44
[+] (depends-on "PKG-SPEC")

lisp/help/core/recipe

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
💡 Please specify URL: in your main package file
2+
💡 Please specify URL in your main package file:
33

44
[+] ;; URL: https://example.com/your/repo/url
55

lisp/help/core/reinstall

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
2-
💡 Make sure you have specify a (package-file ..) directive inside your Eask file!
3-
1+
2+
💡 Make sure you have specified a (package-file ..) directive inside your Eask file!
3+
44
[+] (package-file "PKG-MAIN.el")
5-
5+
66
💡 Or specify package names as arguments
7-
7+
88
$ eask reinstall PKG-1 PKG-2
9-
10-
💡 You would need to first install packages before reinstalling!
9+
10+
💡 You first need to install packages before reinstalling!
1111

1212
Try the command:
1313

lisp/help/core/search

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
💡 You would need to specify queries to do search operations
2+
💡 You need to specify queries to search for
33

44
$ eask search QUERY-1 QUERY-2 ..

lisp/help/core/uninstall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
💡 Make sure you have specify a (package-file ..) inside your Eask file!
32

3+
💡 Make sure you have specified a (package-file ..) inside your Eask file!
44
[+] (package-file "PKG-MAIN.el")
55

66
💡 Or specify package names as arguments

lisp/help/format/elfmt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
💡 You need to specify file(s) you want the elfmt to run
2+
💡 You need to specify file(s) you want elfmt to format
33

44
$ eask format elfmt FILE-1 FILE-2
55

6-
💡 Or edit Eask file with [package-file] or [files] specifier
6+
💡 Or edit the Eask-file with [package-file] or [files] specifier
77

88
[+] (package-file "ENTRY") ; One argument with a string
99
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns

lisp/help/format/elisp-autofmt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
💡 You need to specify file(s) you want the elisp-autofmt to run
2+
💡 You need to specify file(s) you want elisp-autofmt to format
33

44
$ eask format elisp-autofmt FILE-1 FILE-2
55

6-
💡 Or edit Eask file with [package-file] or [files] specifier
6+
💡 Or edit the Eask-file with [package-file] or [files] specifier
77

88
[+] (package-file "ENTRY") ; One argument with a string
99
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns

lisp/help/link/add/error

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
💡 You need the `-pkg.el` file so the `package.el` can recognize your package.
32

3+
💡 You need the `-pkg.el` file so that `package.el` can recognize your package.
44
Options are,
55

66
- [ ] Use `eask generate pkg-file` to create one

lisp/help/lint/checkdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
💡 You need to specify file(s) you want the checkdoc to run
2+
💡 You need to specify file(s) you want checkdoc to run
33

44
$ eask lint checkdoc FILE-1 FILE-2
55

6-
💡 Or edit Eask file with [package-file] or [files] specifier
6+
💡 Or edit the Eask-file with [package-file] or [files] specifier
77

88
[+] (package-file "ENTRY") ; One argument with a string
99
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns

lisp/help/lint/declare

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
💡 You need to specify file(s) you want the check-declare to run
2+
💡 You need to specify file(s) you want check-declare to check
33

44
$ eask lint declare FILE-1 FILE-2
55

6-
💡 Or edit Eask file with [package-file] or [files] specifier
6+
💡 Or edit the Eask-file with [package-file] or [files] specifier
77

88
[+] (package-file "ENTRY") ; One argument with a string
99
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns

lisp/help/lint/elint

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
2-
💡 You need to specify file(s) you want the elint to run
3-
1+
2+
💡 You need to specify file(s) you want elint to check
3+
44
[+] (package-file "ENTRY") ; One argument with a string
55
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns
66

77
For example,
8-
8+
99
[+] (files "*.el")
1010

1111
💡 Tip: You can use the command [files] to show all selected files
12-
12+
1313
$ eask files

lisp/help/lint/elisp-lint

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
2-
💡 You need to specify file(s) you want the elisp-lint to run
3-
1+
2+
3+
💡 You need to specify file(s) you want elisp-lint to check
44
[+] (package-file "ENTRY") ; One argument with a string
55
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns
66

77
For example,
8-
8+
99
[+] (files "*.el")
1010

1111
💡 Tip: You can use the command [files] to show all selected files
12-
12+
1313
$ eask files

0 commit comments

Comments
 (0)