Skip to content

Commit

Permalink
Fix default argument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
purcell committed Aug 18, 2023
1 parent a44f20d commit 302f677
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions justl.el
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,6 @@ They are returned as objects, as per the JSON output of \"just --dump\"."
"Get the default value of argument ARG."
(let-alist arg .default))

(defun justl--arg-default-as-string (arg)
"Get the default value of argument ARG as a string.
Empty string is returned if the arg has no default."
(if arg (format "%s" arg) ""))

(defun justl--justfile-argument ()
"Provides justfile argument with the proper location."
(format "--justfile=%s" (tramp-file-local-name justl-justfile)))
Expand All @@ -416,9 +411,7 @@ Empty string is returned if the arg has no default."
(justl--exec-without-justfile
justl-executable
(cons recipe-name
(mapcar (lambda (arg) (read-from-minibuffer
(format "Just arg for %s: " (justl--arg-name arg))
(justl--arg-default-as-string arg)))
(mapcar 'justl--read-arg
(justl--recipe-args recipe)))))))

(defun justl-exec-default-recipe ()
Expand Down Expand Up @@ -469,7 +462,7 @@ not executed."
justl-executable
(cons (justl--recipe-name recipe)
(append (transient-args 'justl-help-popup)
(mapcar 'justl--arg-default-as-string
(mapcar 'justl--arg-default
(justl--recipe-args recipe)))))
" "))
(unless no-send
Expand Down Expand Up @@ -512,6 +505,15 @@ not executed."
]
])

(defun justl--read-arg (arg)
"Read a value for ARG from the minibuffer."
(let ((default (justl--arg-default arg)))
(read-from-minibuffer
(format "Just arg for `%s': " (justl--arg-name arg))
(if (and default (listp default)) ;; E.g. `(variable some-var)'
(format "%s" default)
default))))

(defun justl-exec-recipe ()
"Execute just recipe."
(interactive)
Expand All @@ -520,9 +522,7 @@ not executed."
justl-executable
(append (transient-args 'justl-help-popup)
(cons (justl--recipe-name recipe)
(mapcar (lambda (arg) (read-from-minibuffer
(format "Just arg for `%s': " (justl--arg-name arg))
(justl--arg-default-as-string arg)))
(mapcar 'justl--read-arg
(justl--recipe-args recipe)))))))

(defun justl--exec-recipe-with-args ()
Expand Down

0 comments on commit 302f677

Please sign in to comment.