aboutsummaryrefslogtreecommitdiff
path: root/guix/ui.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-02-25 23:31:51 +0100
committerLudovic Courtès <ludo@gnu.org>2015-02-26 00:04:36 +0100
commitb3f213893b67620840597213b8f46af1ddfb4934 (patch)
treeabfa807e3a38e60c86e2ff1bf79e2dc55a06acd6 /guix/ui.scm
parent72bfebf58d9203c6a09266dd2a20719bed6e27e9 (diff)
downloadgnu-guix-b3f213893b67620840597213b8f46af1ddfb4934.tar
gnu-guix-b3f213893b67620840597213b8f46af1ddfb4934.tar.gz
ui: Factorize command-line + env. var. option parsing.
* guix/ui.scm (%default-argument-handler, parse-command-line): New procedures. (environment-build-options): Make private. * guix/scripts/archive.scm (guix-archive)[parse-options, parse-options-from]: Remove. Use 'parse-command-line' instead. * guix/scripts/build.scm (guix-build): Likewise. * guix/scripts/environment.scm (guix-environment): Likewise. * guix/scripts/package.scm (guix-package): Likewise. * guix/scripts/system.scm (guix-system): Likewise. * tests/ui.scm (with-environment-variable): New macro. ("parse-command-line"): New test.
Diffstat (limited to 'guix/ui.scm')
-rw-r--r--guix/ui.scm28
1 files changed, 27 insertions, 1 deletions
diff --git a/guix/ui.scm b/guix/ui.scm
index 382b5b1e0d..09cb6f48ff 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -66,7 +66,7 @@
string->generations
string->duration
args-fold*
- environment-build-options
+ parse-command-line
run-guix-command
program-name
guix-warning-port
@@ -754,6 +754,32 @@ reporting."
"Return additional build options passed as environment variables."
(arguments-from-environment-variable "GUIX_BUILD_OPTIONS"))
+(define %default-argument-handler
+ ;; The default handler for non-option command-line arguments.
+ (lambda (arg result)
+ (alist-cons 'argument arg result)))
+
+(define* (parse-command-line args options seeds
+ #:key
+ (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'.
+
+ARGUMENT-HANDLER is called for non-option arguments, like the 'operand-proc'
+parameter of 'args-fold'."
+ (define (parse-options-from args)
+ ;; Actual parsing takes place here.
+ (apply args-fold* args options
+ (lambda (opt name arg . rest)
+ (leave (_ "~A: unrecognized option~%") name))
+ argument-handler
+ seeds))
+
+ (append (parse-options-from args)
+ (parse-options-from (environment-build-options))))
+
(define (show-guix-usage)
(format (current-error-port)
(_ "Try `guix --help' for more information.~%"))