aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-10-27 13:28:00 -0700
committerLudovic Courtès <ludo@gnu.org>2017-10-28 09:45:53 +0200
commita1ff7e1d8dfb86ae1817d4e0db4ddeebd2083e83 (patch)
tree37ae378568444d592f17174bfc90533c55d18a38
parented1f071e98126ceb992faf5f22762f24d36ba9ff (diff)
downloadguix-a1ff7e1d8dfb86ae1817d4e0db4ddeebd2083e83.tar
guix-a1ff7e1d8dfb86ae1817d4e0db4ddeebd2083e83.tar.gz
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.
-rw-r--r--guix/scripts.scm14
-rw-r--r--guix/scripts/challenge.scm8
-rw-r--r--guix/scripts/gc.scm8
-rw-r--r--guix/scripts/graph.scm9
-rw-r--r--guix/scripts/hash.scm9
-rw-r--r--guix/scripts/lint.scm8
-rw-r--r--guix/scripts/refresh.scm8
-rw-r--r--guix/scripts/size.scm8
-rw-r--r--guix/scripts/weather.scm9
9 files changed, 27 insertions, 54 deletions
diff --git a/guix/scripts.scm b/guix/scripts.scm
index 9ff7f25548..4a7ae7baa3 100644
--- a/guix/scripts.scm
+++ b/guix/scripts.scm
@@ -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))))
diff --git a/guix/scripts/challenge.scm b/guix/scripts/challenge.scm
index 5c59fbe21c..f0693ed8df 100644
--- a/guix/scripts/challenge.scm
+++ b/guix/scripts/challenge.scm
@@ -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))
diff --git a/guix/scripts/gc.scm b/guix/scripts/gc.scm
index 0a9719d259..378a47d113 100644
--- a/guix/scripts/gc.scm
+++ b/guix/scripts/gc.scm
@@ -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))))
diff --git a/guix/scripts/graph.scm b/guix/scripts/graph.scm
index d5be442884..6b809d3ade 100644
--- a/guix/scripts/graph.scm
+++ b/guix/scripts/graph.scm
@@ -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
diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm
index 1fa6bb8d1f..cae5d6bcdf 100644
--- a/guix/scripts/hash.scm
+++ b/guix/scripts/hash.scm
@@ -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)
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
index a26f92f49c..0338d4cb13 100644
--- a/guix/scripts/lint.scm
+++ b/guix/scripts/lint.scm
@@ -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
diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm
index d638d744af..852b44b38d 100644
--- a/guix/scripts/refresh.scm
+++ b/guix/scripts/refresh.scm
@@ -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.
diff --git a/guix/scripts/size.scm b/guix/scripts/size.scm
index dee3604174..b7b53e43fb 100644
--- a/guix/scripts/size.scm
+++ b/guix/scripts/size.scm
@@ -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))
diff --git a/guix/scripts/weather.scm b/guix/scripts/weather.scm
index 7f42f9475d..0d4a7fa26b 100644
--- a/guix/scripts/weather.scm
+++ b/guix/scripts/weather.scm
@@ -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)