[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 44ffd6a825 2/2: Treat "-" as a positional arg in 'eshell-eval-usi
From: |
Lars Ingebrigtsen |
Subject: |
master 44ffd6a825 2/2: Treat "-" as a positional arg in 'eshell-eval-using-options' |
Date: |
Tue, 25 Jan 2022 07:31:06 -0500 (EST) |
branch: master
commit 44ffd6a825300fec5e492805bb105d2c8c3d0c1c
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Treat "-" as a positional arg in 'eshell-eval-using-options'
* lisp/eshell/esh-opt.el (eshell--process-args): Treat "-" as a
positional arg.
* lisp/eshell/em-tramp.el (eshell/su): Simplify checking for "-".
* test/lisp/eshell/esh-opt-tests.el
(esh-opt-test/eval-using-options-stdin): New test.
---
lisp/eshell/em-tramp.el | 9 ++-------
lisp/eshell/esh-opt.el | 9 ++++++---
test/lisp/eshell/esh-opt-tests.el | 21 +++++++++++++++++++++
3 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/lisp/eshell/em-tramp.el b/lisp/eshell/em-tramp.el
index 791458822d..2afd4fe066 100644
--- a/lisp/eshell/em-tramp.el
+++ b/lisp/eshell/em-tramp.el
@@ -57,13 +57,12 @@
(autoload 'eshell-parse-command "esh-cmd")
-(defun eshell/su (&rest arguments)
+(defun eshell/su (&rest args)
"Alias \"su\" to call TRAMP.
Uses the system su through TRAMP's su method."
- (setq arguments (eshell-stringify-list (flatten-tree arguments)))
(eshell-eval-using-options
- "su" arguments
+ "su" args
'((?h "help" nil nil "show this usage screen")
(?l "login" nil login "provide a login environment")
(? nil nil login "provide a login environment")
@@ -77,10 +76,6 @@ Become another USER during a login session.")
(prefix (file-remote-p default-directory)))
(dolist (arg args)
(if (string-equal arg "-") (setq login t) (setq user arg)))
- ;; `eshell-eval-using-options' tries to handle "-" as a
- ;; short option; double-check whether the original
- ;; arguments include it.
- (when (member "-" arguments) (setq login t))
(when login (setq dir "~/"))
(if (and prefix
(or
diff --git a/lisp/eshell/esh-opt.el b/lisp/eshell/esh-opt.el
index 8c29fff809..0961e214f4 100644
--- a/lisp/eshell/esh-opt.el
+++ b/lisp/eshell/esh-opt.el
@@ -283,6 +283,9 @@ triggered to say that the switch is unrecognized."
(memq :parse-leading-options-only options))))
(setq arg (nth ai eshell--args))
(if (not (and (stringp arg)
+ ;; A string of length 1 can't be an option; (if
+ ;; it's "-", that generally means stdin).
+ (> (length arg) 1)
(string-match "^-\\(-\\)?\\(.*\\)" arg)))
;; Positional argument found, skip
(setq ai (1+ ai)
@@ -295,9 +298,9 @@ triggered to say that the switch is unrecognized."
(if (> (length switch) 0)
(eshell--process-option name switch 1 ai options opt-vals)
(setq ai (length eshell--args)))
- (while (> (length switch) 0)
- (setq switch (eshell--process-option name switch 0
- ai options opt-vals)))))))
+ (while (> (length switch) 0)
+ (setq switch (eshell--process-option name switch 0
+ ai options opt-vals)))))))
(nconc (mapcar #'cdr opt-vals) eshell--args)))
(provide 'esh-opt)
diff --git a/test/lisp/eshell/esh-opt-tests.el
b/test/lisp/eshell/esh-opt-tests.el
index 4331c02ff5..5b30de414a 100644
--- a/test/lisp/eshell/esh-opt-tests.el
+++ b/test/lisp/eshell/esh-opt-tests.el
@@ -182,6 +182,27 @@
(should (equal ignore-pattern "*.txt"))
(should (equal args '("/some/path")))))
+(ert-deftest esh-opt-test/eval-using-options-stdin ()
+ "Test that \"-\" is a positional arg in `eshell-eval-using-options'."
+ (eshell-eval-using-options
+ "cat" '("-")
+ '((?A "show-all" nil show-all
+ "show all characters"))
+ (should (eq show-all nil))
+ (should (equal args '("-"))))
+ (eshell-eval-using-options
+ "cat" '("-A" "-")
+ '((?A "show-all" nil show-all
+ "show all characters"))
+ (should (eq show-all t))
+ (should (equal args '("-"))))
+ (eshell-eval-using-options
+ "cat" '("-" "-A")
+ '((?A "show-all" nil show-all
+ "show all characters"))
+ (should (eq show-all t))
+ (should (equal args '("-")))))
+
(ert-deftest esh-opt-test/eval-using-options-terminate-options ()
"Test that \"--\" terminates options in `eshell-eval-using-options'."
(eshell-eval-using-options