diff --git a/CHANGELOG.md b/CHANGELOG.md index c28814c7..3053ebc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * fix: Unsilent in Eask-file by default (40d82becaf20f0851e5fc37aa17c5f6871c163a3) * Make better use for `special` commands (#206) +* feat: Accept rest arguments after command line separator (#207) ## 0.9.x > Released Nov 17, 2023 diff --git a/lisp/_prepare.el b/lisp/_prepare.el index e79cbc12..85a73271 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -90,6 +90,20 @@ Arguments FNC and ARGS are used for advice `:around'." (defconst eask-is-pkg (getenv "EASK_IS_PKG") "Eask is pkg.") +(defconst eask-rest-args + (let ((args (getenv "EASK_REST_ARGS"))) + (setq args (split-string args ",")) + args) + "Eask arguments in list after command separator `--'. + +If the argument is `-- hello world'; it will return `(hello world)'.") + +(defun eask-rest-args () + "Eask arguments in string after command separator `--'. + +If the argument is `-- hello world'; it will return `hello world'." + (mapconcat #'identity eask-rest-args " ")) + (defcustom eask-import-timeout 10 "Number of seconds before timing out elisp importation attempts. If nil, never time out." diff --git a/lisp/run/script.el b/lisp/run/script.el index 31bf42b3..36d3e3e5 100644 --- a/lisp/run/script.el +++ b/lisp/run/script.el @@ -44,6 +44,7 @@ ;; ;; We must split up all commands! (setq command (eask-s-replace " && " "\n" command))) + (setq command (concat command " " (eask-rest-args))) (write-region (concat command "\n") nil eask--run-file t)) (defun eask--unmatched-scripts (scripts) diff --git a/src/util.js b/src/util.js index b0ae97d9..ca152d91 100644 --- a/src/util.js +++ b/src/util.js @@ -50,6 +50,16 @@ function escape_str(str) { return str.replaceAll('\"', '\\"'); } +/** + * Return arguments after `--` in list. + */ +function _rest_args() { + let index = process.argv.indexOf('--'); + if (index === -1) + return []; + return process.argv.slice(index + 1); +} + /** * Form CLI arguments into a single string. * @see https://github.com/emacs-eask/cli/issues/128 @@ -119,6 +129,7 @@ function setup_env() { process.env.EASK_INVOCATION = _invocation(); process.env.EASK_HOMEDIR = EASK_HOMEDIR; if (IS_PKG) process.env.EASK_IS_PKG = IS_PKG; + process.env.EASK_REST_ARGS = _rest_args(); if (GITHUB_ACTIONS) { /* XXX: isTTY flag will always be undefined in GitHub Actions; we will have diff --git a/test/commands/local/run.sh b/test/commands/local/run.sh index 7eb9e369..8a68fe32 100644 --- a/test/commands/local/run.sh +++ b/test/commands/local/run.sh @@ -57,9 +57,11 @@ eask recipe eask keywords eask run script eask run script test +eask run script extra -- Extra arguments! eask run script -all eask run command eask run command test +eask run command mini-test-3 -- Extra arguments! eask run command -all # Exection diff --git a/test/fixtures/mini.emacs.pkg.1/Eask b/test/fixtures/mini.emacs.pkg.1/Eask index 25c21181..acfdde6b 100644 --- a/test/fixtures/mini.emacs.pkg.1/Eask +++ b/test/fixtures/mini.emacs.pkg.1/Eask @@ -10,10 +10,14 @@ (files "files/*.el") (script "test" "echo \"Have a nice day!~ ;)\"") +(script "extra" "echo :") (script "info" "eask info") -(eask-defcommand mini-test-1 "Command 1." (message "mini test 1")) -(eask-defcommand mini-test-2 "Command 2." (message "mini test 2")) +(eask-defcommand mini-test-1 "Test command 1." (message "Test 1")) +(eask-defcommand mini-test-2 "Test command 2." (message "Test 2")) +(eask-defcommand mini-test-3 + "Test command 3." + (message "Test 3: %s" eask-rest-args)) (source "gnu") (source "melpa")