mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
ui: Add `args-fold*' and use it.
* guix/ui.scm (args-fold*): New procedure. * guix/scripts/build.scm, guix/scripts/download.scm, guix/scripts/gc.scm, guix/scripts/hash.scm, guix/scripts/import.scm, guix/scripts/package.scm, guix/scripts/pull.scm, guix/scripts/refresh.scm: Use `args-fold*' instead of `args-fold'.
This commit is contained in:
parent
14e2afa74b
commit
a5975cedf2
9 changed files with 63 additions and 49 deletions
|
@ -149,12 +149,12 @@ (define %options
|
|||
(define (guix-build . args)
|
||||
(define (parse-options)
|
||||
;; Return the alist of option values.
|
||||
(args-fold args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
(args-fold* args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
|
||||
(define (register-root paths root)
|
||||
;; Register ROOT as an indirect GC root for all of PATHS.
|
||||
|
|
|
@ -90,12 +90,12 @@ (define fmt-proc
|
|||
(define (guix-download . args)
|
||||
(define (parse-options)
|
||||
;; Return the alist of option values.
|
||||
(args-fold args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
(args-fold* args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
|
||||
(with-error-handling
|
||||
(let* ((opts (parse-options))
|
||||
|
|
|
@ -141,12 +141,12 @@ (define %options
|
|||
(define (guix-gc . args)
|
||||
(define (parse-options)
|
||||
;; Return the alist of option values.
|
||||
(args-fold args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
(args-fold* args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
|
||||
(define (symlink-target file)
|
||||
(let ((s (false-if-exception (lstat file))))
|
||||
|
|
|
@ -90,13 +90,13 @@ (define fmt-proc
|
|||
(define (guix-hash . args)
|
||||
(define (parse-options)
|
||||
;; Return the alist of option values.
|
||||
(args-fold args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "unrecognized option: ~a~%")
|
||||
name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
(args-fold* args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "unrecognized option: ~a~%")
|
||||
name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
|
||||
(let* ((opts (parse-options))
|
||||
(args (filter-map (match-lambda
|
||||
|
|
|
@ -95,12 +95,12 @@ (define %options
|
|||
(define (guix-import . args)
|
||||
(define (parse-options)
|
||||
;; Return the alist of option values.
|
||||
(args-fold args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
(args-fold* args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
|
||||
(let* ((opts (parse-options))
|
||||
(args (filter-map (match-lambda
|
||||
|
|
|
@ -446,12 +446,12 @@ (define %options
|
|||
(define (guix-package . args)
|
||||
(define (parse-options)
|
||||
;; Return the alist of option values.
|
||||
(args-fold args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(leave (_ "~A: extraneous argument~%") arg))
|
||||
%default-options))
|
||||
(args-fold* args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(leave (_ "~A: extraneous argument~%") arg))
|
||||
%default-options))
|
||||
|
||||
(define (guile-missing?)
|
||||
;; Return #t if %GUILE-FOR-BUILD is not available yet.
|
||||
|
|
|
@ -173,12 +173,12 @@ (define %options
|
|||
(define (guix-pull . args)
|
||||
(define (parse-options)
|
||||
;; Return the alist of option values.
|
||||
(args-fold args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(leave (_ "~A: unexpected argument~%") arg))
|
||||
%default-options))
|
||||
(args-fold* args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(leave (_ "~A: unexpected argument~%") arg))
|
||||
%default-options))
|
||||
|
||||
(with-error-handling
|
||||
(let ((opts (parse-options))
|
||||
|
|
|
@ -93,12 +93,12 @@ (define (show-help)
|
|||
(define (guix-refresh . args)
|
||||
(define (parse-options)
|
||||
;; Return the alist of option values.
|
||||
(args-fold args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
(args-fold* args %options
|
||||
(lambda (opt name arg result)
|
||||
(leave (_ "~A: unrecognized option~%") name))
|
||||
(lambda (arg result)
|
||||
(alist-cons 'argument arg result))
|
||||
%default-options))
|
||||
|
||||
(define core-package?
|
||||
(let* ((input->package (match-lambda
|
||||
|
|
14
guix/ui.scm
14
guix/ui.scm
|
@ -29,6 +29,7 @@ (define-module (guix ui)
|
|||
#:use-module (srfi srfi-11)
|
||||
#:use-module (srfi srfi-26)
|
||||
#:use-module (srfi srfi-34)
|
||||
#:use-module (srfi srfi-37)
|
||||
#:use-module (ice-9 match)
|
||||
#:use-module (ice-9 format)
|
||||
#:export (_
|
||||
|
@ -46,6 +47,7 @@ (define-module (guix ui)
|
|||
fill-paragraph
|
||||
string->recutils
|
||||
package->recutils
|
||||
args-fold*
|
||||
run-guix-command
|
||||
program-name
|
||||
guix-warning-port
|
||||
|
@ -370,6 +372,18 @@ (define (description->recutils str)
|
|||
(and=> (package-description p) description->recutils))
|
||||
(newline port))
|
||||
|
||||
(define (args-fold* options unrecognized-option-proc operand-proc . seeds)
|
||||
"A wrapper on top of `args-fold' that does proper user-facing error
|
||||
reporting."
|
||||
(catch 'misc-error
|
||||
(lambda ()
|
||||
(apply args-fold options unrecognized-option-proc
|
||||
operand-proc seeds))
|
||||
(lambda (key proc msg args . rest)
|
||||
;; XXX: MSG is not i18n'd.
|
||||
(leave (_ "invalid argument: ~a~%")
|
||||
(apply format #f msg args)))))
|
||||
|
||||
(define (show-guix-usage)
|
||||
;; TODO: Dynamically generate a summary of available commands.
|
||||
(format (current-error-port)
|
||||
|
|
Loading…
Reference in a new issue