Skip to content

Set error status when help is printed #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/help_exit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Help-Exit

on:
push:
branches:
- master
paths:
- 'eask'
- '**.yml'
- lisp/**
- cmds/**
- src/**
- test/**
pull_request:
branches:
- master
paths-ignore:
- '**.md'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: jcs090218/setup-emacs@master
with:
version: 30.1

- uses: actions/checkout@v4

- name: Prepare Eask (Unix)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: |
chmod -R 777 ./
.github/scripts/setup-eask

- name: Prepare Eask (Windows)
if: matrix.os == 'windows-latest'
run: .github/scripts/setup-eask.ps1

- name: Testing...
run: |
make command-help-exit
44 changes: 42 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,70 @@ command-config:
command-local:
./test/commands/local/run.sh

# new tests which check missing args not covered by existing tests
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

command-analyze:
./test/commands/analyze/dsl/run.sh
./test/commands/analyze/metadata/run.sh
./test/commands/analyze/error/run.sh

command-bump:
./test/commands/bump/run.sh

command-compile:
./test/commands/compile/run.sh

command-concat:
./test/commands/concat/run.sh

command-docker:
./test/commands/docker/run.sh

command-docs:
./test/commands/docs/run.sh

command-eval:
./test/commands/eval/run.sh

command-exec:
./test/commands/exec/run.sh

command-emacs:
./test/commands/emacs/run.sh

command-format:
./test/commands/format/run.sh

command-info:
./test/commands/info/run.sh

command-init:
./test/commands/init/run.sh

command-install:
./test/commands/install/run.sh

command-link:
./test/commands/link/run.sh

command-lint:
./test/commands/lint/run.sh

command-outdated-upgrade:
./test/commands/outdated_upgrade/run.sh

command-recipe:
./test/commands/recipe/run.sh

command-run:
./test/commands/run/run.sh

command-search:
./test/commands/search/run.sh

command-link:
./test/commands/link/run.sh
command-source:
./test/commands/source/run.sh

test-ert:
./test/commands/test/ert/run.sh
Expand Down
2 changes: 1 addition & 1 deletion cmds/run/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const fs = require('fs');
const child_process = require("child_process");

exports.command = ['script [names..]'];
exports.desc = 'Run script nameds [names..]';
exports.desc = 'Run script named [names..]';
exports.builder = yargs => yargs
.positional(
'[names..]', {
Expand Down
31 changes: 24 additions & 7 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,9 @@ Argument ARGS are direct arguments for functions `eask-error' or `eask-warn'."
(declare (indent 0) (debug t))
`(eask-ignore-errors (eask--silent-error ,@body)))

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

(defun eask--trigger-error ()
"Trigger error event."
Expand Down Expand Up @@ -1858,26 +1860,41 @@ Arguments FNC and ARGS are used for advice `:around'."
(eask-msg (ansi-white (buffer-string)))
(eask-msg (concat "''" (spaces-string max-column) "''"))))

(defun eask-help (command)
"Show COMMAND's help instruction."
(defun eask-help (command &optional print-or-exit-code)
"Show COMMAND's help instruction.

When the optional variable PRINT-OR-EXIT-CODE is a number, it will exit with
that code. Set to non-nil would just print the help message without sending
the exit code. The default value `nil' will be replaced by `1'; therefore
would send exit code of `1'."
(let* ((command (eask-2str command)) ; convert to string
(help-file (concat eask-lisp-root "help/" command)))
(help-file (concat eask-lisp-root "help/" command))
;; The default exit code is `1' since `eask-help' prints the help
;; message on user error 99% of the time.
;;
;; TODO: Later replace exit code `1' with readable symbol after
;; the exit code has specified.
(print-or-exit-code (or print-or-exit-code 1)))
(if (file-exists-p help-file)
(with-temp-buffer
(insert-file-contents help-file)
(unless (string-empty-p (buffer-string))
(let ((buf-str (eask--msg-displayable-kwds (buffer-string))))
(erase-buffer)
(insert buf-str))
(eask--help-display)))
(eask-error "Help manual missig %s" help-file))))
(eask--help-display))
;; Exit with code if needed
(cond ((numberp print-or-exit-code)
(eask--exit print-or-exit-code))
(t ))) ; Don't exit with anything else.
(eask-error "Help manual missing %s" help-file))))

;;
;;; Checker

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

(defun eask--check-strings (fmt f p &rest args)
"Test strings (F and P); then print FMT and ARGS if not equal."
Expand Down
2 changes: 1 addition & 1 deletion lisp/core/analyze.el
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ Argument LEVEL and MSG are data from the debug log signal."
;; Default, print help!
(t
(eask-info "(No Eask-files have been checked)")
(eask-help "checker/analyze"))))
(eask-help "core/analyze"))))

;;; core/analyze.el ends here
4 changes: 2 additions & 2 deletions lisp/help/core/analyze
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
💡 You need to specify file(s) you want to Eask checker to check

💡 You need to specify file(s) you want Eask checker to check

$ eask analyze FILE-1 FILE-2
2 changes: 1 addition & 1 deletion lisp/help/core/concat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

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

$ eask concat [names..]
2 changes: 1 addition & 1 deletion lisp/help/core/docs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

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

$ eask docs [names..]
2 changes: 1 addition & 1 deletion lisp/help/core/eval
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

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

$ eask eval [form]
4 changes: 2 additions & 2 deletions lisp/help/core/exec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

💡 You would need to specify the program name in order to make execution!
💡 You need to specify the program name to execute!

$ eask exec <program> [options..]
2 changes: 1 addition & 1 deletion lisp/help/core/info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

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

$ eask init

Expand Down
2 changes: 1 addition & 1 deletion lisp/help/core/install-deps
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

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

[+] (depends-on "PKG-SPEC")
2 changes: 1 addition & 1 deletion lisp/help/core/recipe
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

💡 Please specify URL: in your main package file
💡 Please specify URL in your main package file:

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

Expand Down
14 changes: 7 additions & 7 deletions lisp/help/core/reinstall
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
💡 Make sure you have specify a (package-file ..) directive inside your Eask file!

💡 Make sure you have specified a (package-file ..) directive inside your Eask file!

[+] (package-file "PKG-MAIN.el")

💡 Or specify package names as arguments

$ eask reinstall PKG-1 PKG-2
💡 You would need to first install packages before reinstalling!

💡 You first need to install packages before reinstalling!

Try the command:

Expand Down
2 changes: 1 addition & 1 deletion lisp/help/core/search
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

💡 You would need to specify queries to do search operations
💡 You need to specify queries to search for

$ eask search QUERY-1 QUERY-2 ..
2 changes: 1 addition & 1 deletion lisp/help/core/uninstall
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

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

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

💡 Or specify package names as arguments
Expand Down
4 changes: 2 additions & 2 deletions lisp/help/format/elfmt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

💡 You need to specify file(s) you want the elfmt to run
💡 You need to specify file(s) you want elfmt to format

$ eask format elfmt FILE-1 FILE-2

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

[+] (package-file "ENTRY") ; One argument with a string
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns
Expand Down
4 changes: 2 additions & 2 deletions lisp/help/format/elisp-autofmt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

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

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

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

[+] (package-file "ENTRY") ; One argument with a string
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns
Expand Down
2 changes: 1 addition & 1 deletion lisp/help/link/add/error
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

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

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

- [ ] Use `eask generate pkg-file` to create one
Expand Down
4 changes: 2 additions & 2 deletions lisp/help/lint/checkdoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

💡 You need to specify file(s) you want the checkdoc to run
💡 You need to specify file(s) you want checkdoc to run

$ eask lint checkdoc FILE-1 FILE-2

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

[+] (package-file "ENTRY") ; One argument with a string
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns
Expand Down
4 changes: 2 additions & 2 deletions lisp/help/lint/declare
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

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

$ eask lint declare FILE-1 FILE-2

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

[+] (package-file "ENTRY") ; One argument with a string
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns
Expand Down
10 changes: 5 additions & 5 deletions lisp/help/lint/elint
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
💡 You need to specify file(s) you want the elint to run

💡 You need to specify file(s) you want elint to check

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

For example,

[+] (files "*.el")

💡 Tip: You can use the command [files] to show all selected files

$ eask files
10 changes: 5 additions & 5 deletions lisp/help/lint/elisp-lint
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
💡 You need to specify file(s) you want the elisp-lint to run


💡 You need to specify file(s) you want elisp-lint to check
[+] (package-file "ENTRY") ; One argument with a string
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns

For example,

[+] (files "*.el")

💡 Tip: You can use the command [files] to show all selected files

$ eask files
Loading
Loading