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.master
parent
ed1f071e98
commit
a1ff7e1d8d
|
@ -67,11 +67,13 @@ reporting."
|
||||||
|
|
||||||
(define* (parse-command-line args options seeds
|
(define* (parse-command-line args options seeds
|
||||||
#:key
|
#:key
|
||||||
|
(build-options? #t)
|
||||||
(argument-handler %default-argument-handler))
|
(argument-handler %default-argument-handler))
|
||||||
"Parse the command-line arguments ARGS as well as arguments passed via the
|
"Parse the command-line arguments ARGS according to OPTIONS (a list of
|
||||||
'GUIX_BUILD_OPTIONS' environment variable according to OPTIONS (a list of
|
SRFI-37 options) and return the result, seeded by SEEDS. When BUILD-OPTIONS?
|
||||||
SRFI-37 options) and return the result, seeded by SEEDS.
|
is true, also pass arguments passed via the 'GUIX_BUILD_OPTIONS' environment
|
||||||
Command-line options take precedence those passed via 'GUIX_BUILD_OPTIONS'.
|
variable. Command-line options take precedence those passed via
|
||||||
|
'GUIX_BUILD_OPTIONS'.
|
||||||
|
|
||||||
ARGUMENT-HANDLER is called for non-option arguments, like the 'operand-proc'
|
ARGUMENT-HANDLER is called for non-option arguments, like the 'operand-proc'
|
||||||
parameter of 'args-fold'."
|
parameter of 'args-fold'."
|
||||||
|
@ -85,7 +87,9 @@ parameter of 'args-fold'."
|
||||||
|
|
||||||
(call-with-values
|
(call-with-values
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(parse-options-from (environment-build-options) seeds))
|
(if build-options?
|
||||||
|
(parse-options-from (environment-build-options) seeds)
|
||||||
|
(apply values seeds)))
|
||||||
(lambda seeds
|
(lambda seeds
|
||||||
;; ARGS take precedence over what the environment variable specifies.
|
;; ARGS take precedence over what the environment variable specifies.
|
||||||
(parse-options-from args seeds))))
|
(parse-options-from args seeds))))
|
||||||
|
|
|
@ -278,12 +278,8 @@ Challenge the substitutes for PACKAGE... provided by one or more servers.\n"))
|
||||||
|
|
||||||
(define (guix-challenge . args)
|
(define (guix-challenge . args)
|
||||||
(with-error-handling
|
(with-error-handling
|
||||||
(let* ((opts (args-fold* args %options
|
(let* ((opts (parse-command-line args %options (list %default-options)
|
||||||
(lambda (opt name arg . rest)
|
#:build-options? #f))
|
||||||
(leave (G_ "~A: unrecognized option~%") name))
|
|
||||||
(lambda (arg result)
|
|
||||||
(alist-cons 'argument arg result))
|
|
||||||
%default-options))
|
|
||||||
(files (filter-map (match-lambda
|
(files (filter-map (match-lambda
|
||||||
(('argument . file) file)
|
(('argument . file) file)
|
||||||
(_ #f))
|
(_ #f))
|
||||||
|
|
|
@ -159,12 +159,8 @@ Invoke the garbage collector.\n"))
|
||||||
(define (guix-gc . args)
|
(define (guix-gc . args)
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
;; Return the alist of option values.
|
;; Return the alist of option values.
|
||||||
(args-fold* args %options
|
(parse-command-line args %options (list %default-options)
|
||||||
(lambda (opt name arg result)
|
#:build-options? #f))
|
||||||
(leave (G_ "~A: unrecognized option~%") name))
|
|
||||||
(lambda (arg result)
|
|
||||||
(alist-cons 'argument arg result))
|
|
||||||
%default-options))
|
|
||||||
|
|
||||||
(define (symlink-target file)
|
(define (symlink-target file)
|
||||||
(let ((s (false-if-exception (lstat file))))
|
(let ((s (false-if-exception (lstat file))))
|
||||||
|
|
|
@ -447,12 +447,9 @@ Emit a Graphviz (dot) representation of the dependencies of PACKAGE...\n"))
|
||||||
|
|
||||||
(define (guix-graph . args)
|
(define (guix-graph . args)
|
||||||
(with-error-handling
|
(with-error-handling
|
||||||
(let* ((opts (args-fold* args %options
|
(let* ((opts (parse-command-line args %options
|
||||||
(lambda (opt name arg . rest)
|
(list %default-options)
|
||||||
(leave (G_ "~A: unrecognized option~%") name))
|
#:build-options? #f))
|
||||||
(lambda (arg result)
|
|
||||||
(alist-cons 'argument arg result))
|
|
||||||
%default-options))
|
|
||||||
(backend (assoc-ref opts 'backend))
|
(backend (assoc-ref opts 'backend))
|
||||||
(type (assoc-ref opts 'node-type))
|
(type (assoc-ref opts 'node-type))
|
||||||
(items (filter-map (match-lambda
|
(items (filter-map (match-lambda
|
||||||
|
|
|
@ -104,13 +104,8 @@ and 'hexadecimal' can be used as well).\n"))
|
||||||
(define (guix-hash . args)
|
(define (guix-hash . args)
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
;; Return the alist of option values.
|
;; Return the alist of option values.
|
||||||
(args-fold* args %options
|
(parse-command-line args %options (list %default-options)
|
||||||
(lambda (opt name arg result)
|
#:build-options? #f))
|
||||||
(leave (G_ "unrecognized option: ~a~%")
|
|
||||||
name))
|
|
||||||
(lambda (arg result)
|
|
||||||
(alist-cons 'argument arg result))
|
|
||||||
%default-options))
|
|
||||||
|
|
||||||
(define (vcs-file? file stat)
|
(define (vcs-file? file stat)
|
||||||
(case (stat:type stat)
|
(case (stat:type stat)
|
||||||
|
|
|
@ -1123,12 +1123,8 @@ run the checkers on all packages.\n"))
|
||||||
(define (guix-lint . args)
|
(define (guix-lint . args)
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
;; Return the alist of option values.
|
;; Return the alist of option values.
|
||||||
(args-fold* args %options
|
(parse-command-line args %options (list %default-options)
|
||||||
(lambda (opt name arg result)
|
#:build-options? #f))
|
||||||
(leave (G_ "~A: unrecognized option~%") name))
|
|
||||||
(lambda (arg result)
|
|
||||||
(alist-cons 'argument arg result))
|
|
||||||
%default-options))
|
|
||||||
|
|
||||||
(let* ((opts (parse-options))
|
(let* ((opts (parse-options))
|
||||||
(args (filter-map (match-lambda
|
(args (filter-map (match-lambda
|
||||||
|
|
|
@ -338,12 +338,8 @@ dependent packages are rebuilt: ~{~a~^ ~}~%"
|
||||||
(define (guix-refresh . args)
|
(define (guix-refresh . args)
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
;; Return the alist of option values.
|
;; Return the alist of option values.
|
||||||
(args-fold* args %options
|
(parse-command-line args %options (list %default-options)
|
||||||
(lambda (opt name arg result)
|
#:build-options? #f))
|
||||||
(leave (G_ "~A: unrecognized option~%") name))
|
|
||||||
(lambda (arg result)
|
|
||||||
(alist-cons 'argument arg result))
|
|
||||||
%default-options))
|
|
||||||
|
|
||||||
(define (options->updaters opts)
|
(define (options->updaters opts)
|
||||||
;; Return the list of updaters to use.
|
;; Return the list of updaters to use.
|
||||||
|
|
|
@ -291,12 +291,8 @@ Report the size of PACKAGE and its dependencies.\n"))
|
||||||
|
|
||||||
(define (guix-size . args)
|
(define (guix-size . args)
|
||||||
(with-error-handling
|
(with-error-handling
|
||||||
(let* ((opts (args-fold* args %options
|
(let* ((opts (parse-command-line args %options (list %default-options)
|
||||||
(lambda (opt name arg . rest)
|
#:build-options? #f))
|
||||||
(leave (G_ "~A: unrecognized option~%") name))
|
|
||||||
(lambda (arg result)
|
|
||||||
(alist-cons 'argument arg result))
|
|
||||||
%default-options))
|
|
||||||
(files (filter-map (match-lambda
|
(files (filter-map (match-lambda
|
||||||
(('argument . file) file)
|
(('argument . file) file)
|
||||||
(_ #f))
|
(_ #f))
|
||||||
|
|
|
@ -204,12 +204,9 @@ Report the availability of substitutes.\n"))
|
||||||
|
|
||||||
(define (guix-weather . args)
|
(define (guix-weather . args)
|
||||||
(with-error-handling
|
(with-error-handling
|
||||||
(let* ((opts (args-fold* args %options
|
(let* ((opts (parse-command-line args %options
|
||||||
(lambda (opt name arg . rest)
|
(list %default-options)
|
||||||
(leave (G_ "~A: unrecognized option~%") name))
|
#:build-options? #f))
|
||||||
(lambda (arg result)
|
|
||||||
(alist-cons 'argument arg result))
|
|
||||||
%default-options))
|
|
||||||
(urls (assoc-ref opts 'substitute-urls))
|
(urls (assoc-ref opts 'substitute-urls))
|
||||||
(systems (match (filter-map (match-lambda
|
(systems (match (filter-map (match-lambda
|
||||||
(('system . system) system)
|
(('system . system) system)
|
||||||
|
|
Loading…
Reference in New Issue