summaryrefslogtreecommitdiff
path: root/guix/ui.scm
diff options
context:
space:
mode:
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.~%"))