diff options
| author | Jay Kamat | 2018-05-08 12:36:36 -0700 |
|---|---|---|
| committer | Noam Postavsky | 2018-05-15 19:32:49 -0400 |
| commit | a4c616e27aa48e7d524e0c5cfaf67f17d04989e4 (patch) | |
| tree | 67ac930677e194e8ab3d583568c191c28294d996 /lisp | |
| parent | 92a8230e49a65be48442ee95cf50c90514e48f99 (diff) | |
| download | emacs-a4c616e27aa48e7d524e0c5cfaf67f17d04989e4.tar.gz emacs-a4c616e27aa48e7d524e0c5cfaf67f17d04989e4.zip | |
esh-opt.el: Add a :parse-leading-options-only argument (Bug#28323)
* lisp/eshell/esh-opt.el (eshell-eval-using-options): Add a new
:parse-leading-options-only argument which ignores dash/switch
arguments after the first positional argument.
(eshell--process-args): Abort processing of arguments if we see one
positional argument and :parse-leading-options-only is set.
* lisp/eshell/em-tramp.el (eshell/sudo): Use
:parse-leading-options-only, to avoid parsing subcommand switches as
switches of sudo itself.
* test/lisp/eshell/esh-opt-tests.el: Add tests for new and old behavior.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/eshell/em-tramp.el | 1 | ||||
| -rw-r--r-- | lisp/eshell/esh-opt.el | 17 |
2 files changed, 15 insertions, 3 deletions
diff --git a/lisp/eshell/em-tramp.el b/lisp/eshell/em-tramp.el index 004c4954908..9475f4ed949 100644 --- a/lisp/eshell/em-tramp.el +++ b/lisp/eshell/em-tramp.el | |||
| @@ -107,6 +107,7 @@ Uses the system sudo through TRAMP's sudo method." | |||
| 107 | '((?h "help" nil nil "show this usage screen") | 107 | '((?h "help" nil nil "show this usage screen") |
| 108 | (?u "user" t user "execute a command as another USER") | 108 | (?u "user" t user "execute a command as another USER") |
| 109 | :show-usage | 109 | :show-usage |
| 110 | :parse-leading-options-only | ||
| 110 | :usage "[(-u | --user) USER] COMMAND | 111 | :usage "[(-u | --user) USER] COMMAND |
| 111 | Execute a COMMAND as the superuser or another USER.") | 112 | Execute a COMMAND as the superuser or another USER.") |
| 112 | (throw 'eshell-external | 113 | (throw 'eshell-external |
diff --git a/lisp/eshell/esh-opt.el b/lisp/eshell/esh-opt.el index 67b7d05985d..80eb15359a2 100644 --- a/lisp/eshell/esh-opt.el +++ b/lisp/eshell/esh-opt.el | |||
| @@ -80,6 +80,10 @@ arguments, some do not. The recognized :KEYWORDS are: | |||
| 80 | If present, do not pass MACRO-ARGS through `eshell-flatten-list' | 80 | If present, do not pass MACRO-ARGS through `eshell-flatten-list' |
| 81 | and `eshell-stringify-list'. | 81 | and `eshell-stringify-list'. |
| 82 | 82 | ||
| 83 | :parse-leading-options-only | ||
| 84 | If present, do not parse dash or switch arguments after the first | ||
| 85 | positional argument. Instead, treat them as positional arguments themselves. | ||
| 86 | |||
| 83 | For example, OPTIONS might look like: | 87 | For example, OPTIONS might look like: |
| 84 | 88 | ||
| 85 | ((?C nil nil multi-column \"multi-column display\") | 89 | ((?C nil nil multi-column \"multi-column display\") |
| @@ -245,12 +249,19 @@ switch is unrecognized." | |||
| 245 | (list sym))))) | 249 | (list sym))))) |
| 246 | options))) | 250 | options))) |
| 247 | (ai 0) arg | 251 | (ai 0) arg |
| 248 | (eshell--args args)) | 252 | (eshell--args args) |
| 249 | (while (< ai (length eshell--args)) | 253 | (pos-argument-found nil)) |
| 254 | (while (and (< ai (length eshell--args)) | ||
| 255 | ;; Abort if we saw the first pos argument and option is set | ||
| 256 | (not (and pos-argument-found | ||
| 257 | (memq :parse-leading-options-only options)))) | ||
| 250 | (setq arg (nth ai eshell--args)) | 258 | (setq arg (nth ai eshell--args)) |
| 251 | (if (not (and (stringp arg) | 259 | (if (not (and (stringp arg) |
| 252 | (string-match "^-\\(-\\)?\\(.*\\)" arg))) | 260 | (string-match "^-\\(-\\)?\\(.*\\)" arg))) |
| 253 | (setq ai (1+ ai)) | 261 | ;; Positional argument found, skip |
| 262 | (setq ai (1+ ai) | ||
| 263 | pos-argument-found t) | ||
| 264 | ;; dash or switch argument found, parse | ||
| 254 | (let* ((dash (match-string 1 arg)) | 265 | (let* ((dash (match-string 1 arg)) |
| 255 | (switch (match-string 2 arg))) | 266 | (switch (match-string 2 arg))) |
| 256 | (if (= ai 0) | 267 | (if (= ai 0) |