Skip to content

Commit eb7c1f2

Browse files
authored
feat: Accept rest arguments after command line separator (#207)
* feat: Accept rest arguments after command line separator * changelog * Test extra args * make function private
1 parent 53186b3 commit eb7c1f2

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1010
1111
* fix: Unsilent in Eask-file by default (40d82becaf20f0851e5fc37aa17c5f6871c163a3)
1212
* Make better use for `special` commands (#206)
13+
* feat: Accept rest arguments after command line separator (#207)
1314

1415
## 0.9.x
1516
> Released Nov 17, 2023

lisp/_prepare.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ Arguments FNC and ARGS are used for advice `:around'."
9090
(defconst eask-is-pkg (getenv "EASK_IS_PKG")
9191
"Eask is pkg.")
9292

93+
(defconst eask-rest-args
94+
(let ((args (getenv "EASK_REST_ARGS")))
95+
(setq args (split-string args ","))
96+
args)
97+
"Eask arguments in list after command separator `--'.
98+
99+
If the argument is `-- hello world'; it will return `(hello world)'.")
100+
101+
(defun eask-rest-args ()
102+
"Eask arguments in string after command separator `--'.
103+
104+
If the argument is `-- hello world'; it will return `hello world'."
105+
(mapconcat #'identity eask-rest-args " "))
106+
93107
(defcustom eask-import-timeout 10
94108
"Number of seconds before timing out elisp importation attempts.
95109
If nil, never time out."

lisp/run/script.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
;;
4545
;; We must split up all commands!
4646
(setq command (eask-s-replace " && " "\n" command)))
47+
(setq command (concat command " " (eask-rest-args)))
4748
(write-region (concat command "\n") nil eask--run-file t))
4849

4950
(defun eask--unmatched-scripts (scripts)

src/util.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ function escape_str(str) {
5050
return str.replaceAll('\"', '\\"');
5151
}
5252

53+
/**
54+
* Return arguments after `--` in list.
55+
*/
56+
function _rest_args() {
57+
let index = process.argv.indexOf('--');
58+
if (index === -1)
59+
return [];
60+
return process.argv.slice(index + 1);
61+
}
62+
5363
/**
5464
* Form CLI arguments into a single string.
5565
* @see https://github.com/emacs-eask/cli/issues/128
@@ -119,6 +129,7 @@ function setup_env() {
119129
process.env.EASK_INVOCATION = _invocation();
120130
process.env.EASK_HOMEDIR = EASK_HOMEDIR;
121131
if (IS_PKG) process.env.EASK_IS_PKG = IS_PKG;
132+
process.env.EASK_REST_ARGS = _rest_args();
122133

123134
if (GITHUB_ACTIONS) {
124135
/* XXX: isTTY flag will always be undefined in GitHub Actions; we will have

test/commands/local/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ eask recipe
5757
eask keywords
5858
eask run script
5959
eask run script test
60+
eask run script extra -- Extra arguments!
6061
eask run script -all
6162
eask run command
6263
eask run command test
64+
eask run command mini-test-3 -- Extra arguments!
6365
eask run command -all
6466

6567
# Exection

test/fixtures/mini.emacs.pkg.1/Eask

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
(files "files/*.el")
1111

1212
(script "test" "echo \"Have a nice day!~ ;)\"")
13+
(script "extra" "echo :")
1314
(script "info" "eask info")
1415

15-
(eask-defcommand mini-test-1 "Command 1." (message "mini test 1"))
16-
(eask-defcommand mini-test-2 "Command 2." (message "mini test 2"))
16+
(eask-defcommand mini-test-1 "Test command 1." (message "Test 1"))
17+
(eask-defcommand mini-test-2 "Test command 2." (message "Test 2"))
18+
(eask-defcommand mini-test-3
19+
"Test command 3."
20+
(message "Test 3: %s" eask-rest-args))
1721

1822
(source "gnu")
1923
(source "melpa")

0 commit comments

Comments
 (0)