Skip to content

Commit

Permalink
Simplify (rewrite) command exec (#22)
Browse files Browse the repository at this point in the history
* Test exec

* Test path

* code: revert for Elisp executable

* udpate flag

* Make exec ignore all default yargs options

* no need to tweak commander anymore

* fix exec

* imp with epilogue

* lower output level

* Set verbosity to execution result

* doc: changelog
  • Loading branch information
jcs090218 authored May 28, 2022
1 parent 9ee2bed commit 586ef6c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* Avoid loading package info unless it's needed (#13, #14, and #19)
* Read `-pkg.el` file prior to package-file while exists (#21)
* Simplify (rewrite) command exec (#22)

## 0.6.17
> Released Mar 5, 2022
Expand Down
13 changes: 6 additions & 7 deletions cmds/core/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
"use strict";

exports.command = ['exec [args..]'];
exports.desc = 'execute command with correct load-path set up';
exports.builder = {
args: {
description: 'execution arguments',
requiresArg: false,
type: 'array',
},
exports.desc = 'execute command with correct environemnt PATH set up';
exports.builder = async (yargs) => {
yargs.help(false);
yargs.version(false);
yargs.getOptions().narg = [];
//console.log(yargs.getOptions());
};

exports.handler = async (argv) => {
Expand Down
17 changes: 9 additions & 8 deletions eask
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ Eask is a command-line tool that helps you build, lint, and test Emacs Lisp pack
Usage: eask <command> [options..]`;

const epilogue = `For more informatiion, find the manual at https://emacs-eask.github.io/`;

yargs
.usage(usage)
.scriptName('')
.commandDir('cmds', {
recurse: true,
.epilogue(epilogue)
.commandDir('cmds', { recurse: true, })
.command({
command: '*',
handler() { yargs.showHelp(); }
})
.showHelpOnFail(true)
.help(
'help',
'Show usage instructions.'
'Show usage instructions'
)
.command({
command: '*',
handler() { yargs.showHelp(); }
})
.option('global', {
description: 'change default workspace to ~/.emacs.d/',
alias: 'g',
Expand Down Expand Up @@ -99,4 +100,4 @@ yargs
})
.demandCommand()
.wrap(yargs.terminalWidth())
.help().argv;
.argv;
4 changes: 3 additions & 1 deletion lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ the `eask-start' execution.")
(eask-with-progress
(ansi-green "Updating environment PATHs... ")
(eask-with-verbosity 'debug
(eask--update-exec-path) (eask--update-load-path))
(eask--update-exec-path) (eask--update-load-path)
(setenv "PATH" (string-join exec-path path-separator))
(setenv "EMACSLOADPATH" (string-join load-path path-separator)))
(ansi-green "done ✓")))

(defvar eask--package-initialized nil
Expand Down
24 changes: 8 additions & 16 deletions lisp/core/exec.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,26 @@

(defun eask--shell-command (command)
"Wrap `shell-command' with better output to terminal."
(eask-info "Executing command: %s" command)
(let ((code (shell-command command "*output*" "*error*")))
(eask-info "Start command: %s" command)
(let ((code (eask-with-verbosity 'debug
(shell-command command "*output*" "*error*"))))
(if (zerop code)
(eask-with-verbosity 'debug
(with-current-buffer "*output*" (eask-msg (buffer-string))))
(with-current-buffer "*output*" (eask-msg (buffer-string)))
(with-current-buffer "*error*" (eask-msg (ansi-red (buffer-string))))
(eask-error "Error from the execution, exit code %s" code))))

(eask-start
(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
;; XXX This is the hack by adding all `bin' folders from local elpa.
(eask-setup-paths)
(setq commander-args (cddr eask-argv)) ; by pass `--' as well
(if-let ((name (eask-argv 1)))
(or
;; 1) For Elisp executable (github-elpa)
(let ((program (executable-find name))) (ignore-errors (load program t t)))
;; 2) Fallback executable isn't a pure elisp file (ert-runner, elsa, etc)
;;
;; This wouldn't work with packages that don't execute tasks during the
;; load time.
(let ((el (locate-library name))) (ignore-errors (load el t t)))
;; 3) Execute `shell-command'
;;
;; TODO: `shell-command' would jump out of Emacs and does not share the
;; same environment PATH.
(let ((program (executable-find name))) (ignore-errors (load program nil t)))
;; 2) Execute `shell-command'
(let* ((program (or (executable-find name) name))
(command (mapconcat #'identity (append (list program) commander-args) " ")))
(commands (cddr (eask-args)))
(command (mapconcat #'identity (append (list program) commands) " ")))
(eask--shell-command command)))
(eask-info "✗ (No exeuction output)")
(eask-help 'exec)))
Expand Down

0 comments on commit 586ef6c

Please sign in to comment.