Skip to content

Commit

Permalink
feat: Accept rest arguments after command line separator (#207)
Browse files Browse the repository at this point in the history
* feat: Accept rest arguments after command line separator

* changelog

* Test extra args

* make function private
  • Loading branch information
jcs090218 committed Dec 3, 2023
1 parent 53186b3 commit eb7c1f2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 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
* 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
Expand Down
14 changes: 14 additions & 0 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
1 change: 1 addition & 0 deletions lisp/run/script.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/commands/local/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions test/fixtures/mini.emacs.pkg.1/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit eb7c1f2

Please sign in to comment.