fix PR 13970 is a slightly less ugly way
This commit is contained in:
parent
ef13798cd5
commit
908b036347
|
@ -131,14 +131,17 @@
|
||||||
[callback (lambda (b e)
|
[callback (lambda (b e)
|
||||||
(define res (compute-cmd-line))
|
(define res (compute-cmd-line))
|
||||||
(in-terminal
|
(in-terminal
|
||||||
(case (car res)
|
(case (cmdline-which res)
|
||||||
[(install) (string-constant install-pkg-abort-install)]
|
[(install) (string-constant install-pkg-abort-install)]
|
||||||
[(update) (string-constant install-pkg-abort-update)])
|
[(update) (string-constant install-pkg-abort-update)])
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(define action (case (car res)
|
(define action (case (cmdline-which res)
|
||||||
[(install) pkg-install-command]
|
[(install) pkg-install-command]
|
||||||
[(update) pkg-update-command]))
|
[(update) pkg-update-command]))
|
||||||
(apply/keywords action (cdr res))))
|
(keyword-apply action
|
||||||
|
(cmdline-kwds res)
|
||||||
|
(cmdline-kwd-args res)
|
||||||
|
(cmdline-args res))))
|
||||||
(reset-installed-pkgs!))]))
|
(reset-installed-pkgs!))]))
|
||||||
|
|
||||||
(define/private (reset-installed-pkgs!)
|
(define/private (reset-installed-pkgs!)
|
||||||
|
@ -418,16 +421,10 @@
|
||||||
[(4) 'search-auto]))
|
[(4) 'search-auto]))
|
||||||
|
|
||||||
(define/private (adjust-cmd-line)
|
(define/private (adjust-cmd-line)
|
||||||
(define (convert-to-string s)
|
(define (possibly-quote-string s)
|
||||||
(cond
|
(if (regexp-match #rx" " s)
|
||||||
[(string? s)
|
(string-append "\"" s "\"")
|
||||||
(if (regexp-match #rx" " s)
|
s))
|
||||||
(string-append "\"" s "\"")
|
|
||||||
s)]
|
|
||||||
[(keyword? s) (regexp-replace #rx"^#:" (format "~a" s) "--")]
|
|
||||||
[(symbol? s) (symbol->string s)]
|
|
||||||
[(boolean? s) #f]
|
|
||||||
[else (error 'convert-to-string "unk ~s" s)]))
|
|
||||||
(define cmd-line (compute-cmd-line))
|
(define cmd-line (compute-cmd-line))
|
||||||
(send cmdline-msg set-label
|
(send cmdline-msg set-label
|
||||||
(if cmd-line
|
(if cmd-line
|
||||||
|
@ -436,57 +433,51 @@
|
||||||
"raco.exe"
|
"raco.exe"
|
||||||
"raco")
|
"raco")
|
||||||
" pkg "
|
" pkg "
|
||||||
|
(format "~a " (cmdline-which cmd-line))
|
||||||
|
(apply
|
||||||
|
string-append
|
||||||
|
(add-between
|
||||||
|
(map (λ (kwd kwd-arg)
|
||||||
|
(format "--~a ~s"
|
||||||
|
(regexp-replace #rx"^#:" (format "~a" kwd) "")
|
||||||
|
kwd-arg))
|
||||||
|
(cmdline-kwds cmd-line)
|
||||||
|
(cmdline-kwd-args cmd-line))
|
||||||
|
" "))
|
||||||
(apply string-append
|
(apply string-append
|
||||||
(add-between
|
(map (λ (x) (format " ~a" (possibly-quote-string x)))
|
||||||
(filter values (map convert-to-string cmd-line))
|
(cmdline-args cmd-line))))
|
||||||
" ")))
|
|
||||||
"")))
|
"")))
|
||||||
|
|
||||||
|
(struct cmdline (which kwds kwd-args args) #:transparent)
|
||||||
(define/private (compute-cmd-line)
|
(define/private (compute-cmd-line)
|
||||||
(define the-pkg
|
(define the-pkg
|
||||||
(cond
|
(cond
|
||||||
[(and (equal? 'update (get-current-action))
|
[(and (equal? 'update (get-current-action))
|
||||||
(package-source->name (send tf get-value)))
|
(package-source->name (send tf get-value)))
|
||||||
=>
|
=>
|
||||||
values]
|
values]
|
||||||
[else (send tf get-value)]))
|
[else (send tf get-value)]))
|
||||||
(and (not (equal? the-pkg ""))
|
(cond
|
||||||
(cons (get-current-action)
|
[(equal? the-pkg "") #f]
|
||||||
(append
|
[else
|
||||||
(if (and (send cb is-enabled?) (send cb get-value))
|
(define kwds '())
|
||||||
'(#:force #t)
|
(define kwd-args '())
|
||||||
'())
|
(define (add-kwd-arg kwd arg)
|
||||||
(if (selected-type)
|
(set! kwds (cons kwd kwds))
|
||||||
(list '#:type (selected-type))
|
(set! kwd-args (cons arg kwd-args)))
|
||||||
'())
|
(when (and (send cb is-enabled?) (send cb get-value))
|
||||||
(let ([scope (selected-scope)])
|
(add-kwd-arg '#:force #t))
|
||||||
(if (equal? scope (default-pkg-scope))
|
(when (selected-type)
|
||||||
'()
|
(add-kwd-arg '#:type (selected-type)))
|
||||||
(list '#:scope scope)))
|
(let ([scope (selected-scope)])
|
||||||
(list '#:deps (get-deps-selected-type))
|
(unless (equal? scope (default-pkg-scope))
|
||||||
(list the-pkg)))))
|
(add-kwd-arg '#:scope scope)))
|
||||||
|
(add-kwd-arg '#:deps (get-deps-selected-type))
|
||||||
|
(cmdline (get-current-action) kwds kwd-args (list the-pkg))]))
|
||||||
|
|
||||||
(define/override (on-superwindow-show on?)
|
(define/override (on-superwindow-show on?)
|
||||||
(when on?
|
(when on?
|
||||||
(reset-installed-pkgs!)))
|
(reset-installed-pkgs!)))
|
||||||
|
|
||||||
;; Pull keyword arguments out of the list `all-args';
|
|
||||||
;; assumes that no keyword is intended as an argument value.
|
|
||||||
;; (This seems ugly.)
|
|
||||||
(define/private (apply/keywords proc all-args)
|
|
||||||
(define-values (args kws kw-vals)
|
|
||||||
(let loop ([args all-args] [rev-args null] [kws+vals null])
|
|
||||||
(cond
|
|
||||||
[(null? args)
|
|
||||||
(let ([kws+vals (sort kws+vals keyword<? #:key car)])
|
|
||||||
(values (reverse rev-args)
|
|
||||||
(map car kws+vals)
|
|
||||||
(map cdr kws+vals)))]
|
|
||||||
[(keyword? (car args))
|
|
||||||
(loop (cddr args) rev-args (cons (cons (car args) (cadr args))
|
|
||||||
kws+vals))]
|
|
||||||
[else
|
|
||||||
(loop (cdr args) (cons (car args) rev-args) kws+vals)])))
|
|
||||||
(keyword-apply proc kws kw-vals args))
|
|
||||||
|
|
||||||
(adjust-all)))
|
(adjust-all)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user