scripts: Factorize option parsing sans 'GUIX_BUILD_OPTIONS'.

* guix/scripts.scm (parse-command-line): Add #:build-options? parameter
and honor it.
* guix/scripts/challenge.scm (guix-challenge): Use 'parse-command-line'
with #:build-options? #f instead of 'args-fold*'.
* guix/scripts/gc.scm (guix-gc): Likewise.
* guix/scripts/graph.scm (guix-graph): Likewise.
* guix/scripts/hash.scm (guix-hash): Likewise.
* guix/scripts/lint.scm (guix-lint): Likewise.
* guix/scripts/refresh.scm (guix-refresh): Likewise.
* guix/scripts/size.scm (guix-size): Likewise.
* guix/scripts/weather.scm (guix-weather): Likewise.
This commit is contained in:
Ludovic Courtès 2017-10-27 13:28:00 -07:00
parent ed1f071e98
commit a1ff7e1d8d
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
9 changed files with 27 additions and 54 deletions

View File

@ -67,11 +67,13 @@ reporting."
(define* (parse-command-line args options seeds
#:key
(build-options? #t)
(argument-handler %default-argument-handler))
"Parse the command-line arguments ARGS as well as arguments passed via the
'GUIX_BUILD_OPTIONS' environment variable according to OPTIONS (a list of
SRFI-37 options) and return the result, seeded by SEEDS.
Command-line options take precedence those passed via 'GUIX_BUILD_OPTIONS'.
"Parse the command-line arguments ARGS according to OPTIONS (a list of
SRFI-37 options) and return the result, seeded by SEEDS. When BUILD-OPTIONS?
is true, also pass arguments passed via the 'GUIX_BUILD_OPTIONS' environment
variable. Command-line options take precedence those passed via
'GUIX_BUILD_OPTIONS'.
ARGUMENT-HANDLER is called for non-option arguments, like the 'operand-proc'
parameter of 'args-fold'."
@ -85,7 +87,9 @@ parameter of 'args-fold'."
(call-with-values
(lambda ()
(parse-options-from (environment-build-options) seeds))
(if build-options?
(parse-options-from (environment-build-options) seeds)
(apply values seeds)))
(lambda seeds
;; ARGS take precedence over what the environment variable specifies.
(parse-options-from args seeds))))

View File

@ -278,12 +278,8 @@ Challenge the substitutes for PACKAGE... provided by one or more servers.\n"))
(define (guix-challenge . args)
(with-error-handling
(let* ((opts (args-fold* args %options
(lambda (opt name arg . rest)
(leave (G_ "~A: unrecognized option~%") name))
(lambda (arg result)
(alist-cons 'argument arg result))
%default-options))
(let* ((opts (parse-command-line args %options (list %default-options)
#:build-options? #f))
(files (filter-map (match-lambda
(('argument . file) file)
(_ #f))

View File

@ -159,12 +159,8 @@ Invoke the garbage collector.\n"))
(define (guix-gc . args)
(define (parse-options)
;; Return the alist of option values.
(args-fold* args %options
(lambda (opt name arg result)
(leave (G_ "~A: unrecognized option~%") name))
(lambda (arg result)
(alist-cons 'argument arg result))
%default-options))
(parse-command-line args %options (list %default-options)
#:build-options? #f))
(define (symlink-target file)
(let ((s (false-if-exception (lstat file))))

View File

@ -447,12 +447,9 @@ Emit a Graphviz (dot) representation of the dependencies of PACKAGE...\n"))
(define (guix-graph . args)
(with-error-handling
(let* ((opts (args-fold* args %options
(lambda (opt name arg . rest)
(leave (G_ "~A: unrecognized option~%") name))
(lambda (arg result)
(alist-cons 'argument arg result))
%default-options))
(let* ((opts (parse-command-line args %options
(list %default-options)
#:build-options? #f))
(backend (assoc-ref opts 'backend))
(type (assoc-ref opts 'node-type))
(items (filter-map (match-lambda

View File

@ -104,13 +104,8 @@ and 'hexadecimal' can be used as well).\n"))
(define (guix-hash . args)
(define (parse-options)
;; Return the alist of option values.
(args-fold* args %options
(lambda (opt name arg result)
(leave (G_ "unrecognized option: ~a~%")
name))
(lambda (arg result)
(alist-cons 'argument arg result))
%default-options))
(parse-command-line args %options (list %default-options)
#:build-options? #f))
(define (vcs-file? file stat)
(case (stat:type stat)

View File

@ -1123,12 +1123,8 @@ run the checkers on all packages.\n"))
(define (guix-lint . args)
(define (parse-options)
;; Return the alist of option values.
(args-fold* args %options
(lambda (opt name arg result)
(leave (G_ "~A: unrecognized option~%") name))
(lambda (arg result)
(alist-cons 'argument arg result))
%default-options))
(parse-command-line args %options (list %default-options)
#:build-options? #f))
(let* ((opts (parse-options))
(args (filter-map (match-lambda

View File

@ -338,12 +338,8 @@ dependent packages are rebuilt: ~{~a~^ ~}~%"
(define (guix-refresh . args)
(define (parse-options)
;; Return the alist of option values.
(args-fold* args %options
(lambda (opt name arg result)
(leave (G_ "~A: unrecognized option~%") name))
(lambda (arg result)
(alist-cons 'argument arg result))
%default-options))
(parse-command-line args %options (list %default-options)
#:build-options? #f))
(define (options->updaters opts)
;; Return the list of updaters to use.

View File

@ -291,12 +291,8 @@ Report the size of PACKAGE and its dependencies.\n"))
(define (guix-size . args)
(with-error-handling
(let* ((opts (args-fold* args %options
(lambda (opt name arg . rest)
(leave (G_ "~A: unrecognized option~%") name))
(lambda (arg result)
(alist-cons 'argument arg result))
%default-options))
(let* ((opts (parse-command-line args %options (list %default-options)
#:build-options? #f))
(files (filter-map (match-lambda
(('argument . file) file)
(_ #f))

View File

@ -204,12 +204,9 @@ Report the availability of substitutes.\n"))
(define (guix-weather . args)
(with-error-handling
(let* ((opts (args-fold* args %options
(lambda (opt name arg . rest)
(leave (G_ "~A: unrecognized option~%") name))
(lambda (arg result)
(alist-cons 'argument arg result))
%default-options))
(let* ((opts (parse-command-line args %options
(list %default-options)
#:build-options? #f))
(urls (assoc-ref opts 'substitute-urls))
(systems (match (filter-map (match-lambda
(('system . system) system)