gnu: Add pingus.
[jackhill/guix/guix.git] / guix / ui.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
8fa3e6b3 2;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
e49951eb 3;;; Copyright © 2013 Mark H Weaver <mhw@netris.org>
98eb8cbe 4;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
073c34d7 5;;;
233e7676 6;;; This file is part of GNU Guix.
073c34d7 7;;;
233e7676 8;;; GNU Guix is free software; you can redistribute it and/or modify it
073c34d7
LC
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
233e7676 13;;; GNU Guix is distributed in the hope that it will be useful, but
073c34d7
LC
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
233e7676 19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
073c34d7
LC
20
21(define-module (guix ui)
22 #:use-module (guix utils)
23 #:use-module (guix store)
cdd5d6f9 24 #:use-module (guix config)
073c34d7 25 #:use-module (guix packages)
9b222abe 26 #:use-module (guix build-system)
9bb2b96a 27 #:use-module (guix derivations)
299112d3
LC
28 #:use-module ((guix licenses) #:select (license? license-name))
29 #:use-module (srfi srfi-1)
30 #:use-module (srfi srfi-11)
2cd09108 31 #:use-module (srfi srfi-19)
073c34d7
LC
32 #:use-module (srfi srfi-26)
33 #:use-module (srfi srfi-34)
c1d52c71 34 #:use-module (srfi srfi-35)
a5975ced 35 #:use-module (srfi srfi-37)
e31ff8b8 36 #:autoload (ice-9 ftw) (scandir)
64fc89b6 37 #:use-module (ice-9 match)
9bb2b96a 38 #:use-module (ice-9 format)
2cd09108 39 #:use-module (ice-9 regex)
073c34d7
LC
40 #:export (_
41 N_
ee764179 42 P_
073c34d7 43 leave
cdd5d6f9 44 show-version-and-exit
3441e164 45 show-bug-report-information
969e678e 46 string->number*
1d6243cf 47 size->number
9bb2b96a 48 show-what-to-build
073c34d7 49 call-with-error-handling
64fc89b6 50 with-error-handling
ac5de156 51 read/eval
eb0880e7 52 read/eval-package-expression
299112d3 53 location->string
c61b026e 54 switch-symlinks
f651b477 55 config-directory
299112d3
LC
56 fill-paragraph
57 string->recutils
e49951eb 58 package->recutils
2876b989 59 package-specification->name+version+output
2cd09108
NK
60 string->generations
61 string->duration
a5975ced 62 args-fold*
e49951eb 63 run-guix-command
a2011be5
LC
64 program-name
65 guix-warning-port
66 warning
e49951eb 67 guix-main))
073c34d7
LC
68
69;;; Commentary:
70;;;
71;;; User interface facilities for command-line tools.
72;;;
73;;; Code:
74
75(define %gettext-domain
ee764179 76 ;; Text domain for strings used in the tools.
073c34d7
LC
77 "guix")
78
ee764179
LC
79(define %package-text-domain
80 ;; Text domain for package synopses and descriptions.
81 "guix-packages")
82
073c34d7
LC
83(define _ (cut gettext <> %gettext-domain))
84(define N_ (cut ngettext <> <> <> %gettext-domain))
ee764179 85(define P_ (cut gettext <> %package-text-domain))
073c34d7 86
b2a886f6
LC
87(define-syntax-rule (define-diagnostic name prefix)
88 "Create a diagnostic macro (i.e., NAME), which will prepend PREFIX to all
89messages."
90 (define-syntax name
91 (lambda (x)
92 (define (augmented-format-string fmt)
93 (string-append "~:[~*~;guix ~a: ~]~a" (syntax->datum fmt)))
94
89d02b98
LC
95 (syntax-case x ()
96 ((name (underscore fmt) args (... ...))
97 (and (string? (syntax->datum #'fmt))
98 (free-identifier=? #'underscore #'_))
b2a886f6
LC
99 (with-syntax ((fmt* (augmented-format-string #'fmt))
100 (prefix (datum->syntax x prefix)))
101 #'(format (guix-warning-port) (gettext fmt*)
102 (program-name) (program-name) prefix
103 args (... ...))))
89d02b98 104 ((name (N-underscore singular plural n) args (... ...))
b2a886f6 105 (and (string? (syntax->datum #'singular))
89d02b98
LC
106 (string? (syntax->datum #'plural))
107 (free-identifier=? #'N-underscore #'N_))
b2a886f6
LC
108 (with-syntax ((s (augmented-format-string #'singular))
109 (p (augmented-format-string #'plural))
110 (prefix (datum->syntax x prefix)))
111 #'(format (guix-warning-port)
112 (ngettext s p n %gettext-domain)
113 (program-name) (program-name) prefix
114 args (... ...))))))))
115
116(define-diagnostic warning "warning: ") ; emit a warning
117
118(define-diagnostic report-error "error: ")
119(define-syntax-rule (leave args ...)
120 "Emit an error message and exit."
121 (begin
122 (report-error args ...)
123 (exit 1)))
124
125(define (install-locale)
126 "Install the current locale settings."
127 (catch 'system-error
128 (lambda _
129 (setlocale LC_ALL ""))
130 (lambda args
131 (warning (_ "failed to install locale: ~a~%")
132 (strerror (system-error-errno args))))))
133
e49951eb 134(define (initialize-guix)
633f045f 135 "Perform the usual initialization for stand-alone Guix commands."
e49951eb 136 (install-locale)
39e9f95d 137 (textdomain %gettext-domain)
e14c3929
LC
138
139 ;; Ignore SIGPIPE. If the daemon closes the connection, we prefer to be
140 ;; notified via an EPIPE later.
141 (sigaction SIGPIPE SIG_IGN)
142
e49951eb
MW
143 (setvbuf (current-output-port) _IOLBF)
144 (setvbuf (current-error-port) _IOLBF))
145
cdd5d6f9
LC
146(define* (show-version-and-exit #:optional (command (car (command-line))))
147 "Display version information for COMMAND and `(exit 0)'."
148 (simple-format #t "~a (~a) ~a~%"
149 command %guix-package-name %guix-version)
c5e0eb28 150 (display (_ "Copyright (C) 2014 the Guix authors
64a967cc
LC
151License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
152This is free software: you are free to change and redistribute it.
153There is NO WARRANTY, to the extent permitted by law.
154"))
cdd5d6f9
LC
155 (exit 0))
156
3441e164
LC
157(define (show-bug-report-information)
158 (format #t (_ "
159Report bugs to: ~a.") %guix-bug-report-address)
160 (format #t (_ "
161~a home page: <~a>") %guix-package-name %guix-home-page-url)
162 (display (_ "
163General help using GNU software: <http://www.gnu.org/gethelp/>"))
164 (newline))
165
969e678e
LC
166(define (string->number* str)
167 "Like `string->number', but error out with an error message on failure."
168 (or (string->number str)
169 (leave (_ "~a: invalid number~%") str)))
170
1d6243cf
LC
171(define (size->number str)
172 "Convert STR, a storage measurement representation such as \"1024\" or
173\"1MiB\", to a number of bytes. Raise an error if STR could not be
174interpreted."
175 (define unit-pos
176 (string-rindex str char-set:digit))
177
178 (define unit
179 (and unit-pos (substring str (+ 1 unit-pos))))
180
181 (let* ((numstr (if unit-pos
182 (substring str 0 (+ 1 unit-pos))
183 str))
184 (num (string->number numstr)))
185 (unless num
186 (leave (_ "invalid number: ~a~%") numstr))
187
188 ((compose inexact->exact round)
189 (* num
190 (match unit
191 ("KiB" (expt 2 10))
192 ("MiB" (expt 2 20))
193 ("GiB" (expt 2 30))
194 ("TiB" (expt 2 40))
195 ("KB" (expt 10 3))
196 ("MB" (expt 10 6))
197 ("GB" (expt 10 9))
198 ("TB" (expt 10 12))
199 ("" 1)
200 (_
201 (leave (_ "unknown unit: ~a~%") unit)))))))
202
073c34d7
LC
203(define (call-with-error-handling thunk)
204 "Call THUNK within a user-friendly error handler."
205 (guard (c ((package-input-error? c)
206 (let* ((package (package-error-package c))
207 (input (package-error-invalid-input c))
208 (location (package-location package))
209 (file (location-file location))
210 (line (location-line location))
211 (column (location-column location)))
98eb8cbe 212 (leave (_ "~a:~a:~a: package `~a' has an invalid input: ~s~%")
073c34d7
LC
213 file line column
214 (package-full-name package) input)))
9b222abe
LC
215 ((package-cross-build-system-error? c)
216 (let* ((package (package-error-package c))
217 (loc (package-location package))
218 (system (package-build-system package)))
219 (leave (_ "~a: ~a: build system `~a' does not support cross builds~%")
220 (location->string loc)
221 (package-full-name package)
222 (build-system-name system))))
ef86c39f 223 ((nix-connection-error? c)
98eb8cbe 224 (leave (_ "failed to connect to `~a': ~a~%")
ef86c39f
LC
225 (nix-connection-error-file c)
226 (strerror (nix-connection-error-code c))))
073c34d7
LC
227 ((nix-protocol-error? c)
228 ;; FIXME: Server-provided error messages aren't i18n'd.
98eb8cbe 229 (leave (_ "build failed: ~a~%")
c1d52c71
LC
230 (nix-protocol-error-message c)))
231 ((message-condition? c)
232 ;; Normally '&message' error conditions have an i18n'd message.
233 (leave (_ "~a~%") (gettext (condition-message c)))))
e14c3929
LC
234 ;; Catch EPIPE and the likes.
235 (catch 'system-error
236 thunk
bde8c0e6
LC
237 (lambda (key proc format-string format-args . rest)
238 (leave (_ "~a: ~a~%") proc
239 (apply format #f format-string format-args))))))
073c34d7 240
ac5de156
LC
241(define (read/eval str)
242 "Read and evaluate STR, raising an error if something goes wrong."
eb0880e7
LC
243 (let ((exp (catch #t
244 (lambda ()
245 (call-with-input-string str read))
246 (lambda args
247 (leave (_ "failed to read expression ~s: ~s~%")
248 str args)))))
ac5de156
LC
249 (catch #t
250 (lambda ()
ada3df03 251 (eval exp the-root-module))
ac5de156
LC
252 (lambda args
253 (leave (_ "failed to evaluate expression `~a': ~s~%")
254 exp args)))))
255
256(define (read/eval-package-expression str)
257 "Read and evaluate STR and return the package it refers to, or exit an
258error."
259 (match (read/eval str)
260 ((? package? p) p)
261 (_
262 (leave (_ "expression ~s does not evaluate to a package~%")
263 str))))
eb0880e7 264
dd36b51b
LC
265(define* (show-what-to-build store drv
266 #:key dry-run? (use-substitutes? #t))
9bb2b96a 267 "Show what will or would (depending on DRY-RUN?) be built in realizing the
4d60610a 268derivations listed in DRV. Return #t if there's something to build, #f
dd36b51b
LC
269otherwise. When USE-SUBSTITUTES?, check and report what is prerequisites are
270available for download."
52ddf2ae
LC
271 (define (built-or-substitutable? drv)
272 (let ((out (derivation->output-path drv)))
273 ;; If DRV has zero outputs, OUT is #f.
274 (or (not out)
275 (or (valid-path? store out)
276 (and use-substitutes?
277 (has-substitutes? store out))))))
278
dd36b51b 279 (let*-values (((build download)
59688fc4
LC
280 (fold2 (lambda (drv build download)
281 (let-values (((b d)
282 (derivation-prerequisites-to-build
283 store drv
284 #:use-substitutes?
285 use-substitutes?)))
286 (values (append b build)
287 (append d download))))
dd36b51b
LC
288 '() '()
289 drv))
290 ((build) ; add the DRV themselves
291 (delete-duplicates
59688fc4 292 (append (map derivation-file-name
52ddf2ae 293 (remove built-or-substitutable? drv))
dd36b51b
LC
294 (map derivation-input-path build))))
295 ((download) ; add the references of DOWNLOAD
1a8b7834
LC
296 (if use-substitutes?
297 (delete-duplicates
298 (append download
299 (remove (cut valid-path? store <>)
300 (append-map
301 substitutable-references
302 (substitutable-path-info store
303 download)))))
304 download)))
00554b2a 305 ;; TODO: Show the installed size of DOWNLOAD.
9bb2b96a 306 (if dry-run?
dd36b51b
LC
307 (begin
308 (format (current-error-port)
83e61a73
LC
309 (N_ "~:[The following derivation would be built:~%~{ ~a~%~}~;~]"
310 "~:[The following derivations would be built:~%~{ ~a~%~}~;~]"
dd36b51b
LC
311 (length build))
312 (null? build) build)
313 (format (current-error-port)
83e61a73
LC
314 (N_ "~:[The following file would be downloaded:~%~{ ~a~%~}~;~]"
315 "~:[The following files would be downloaded:~%~{ ~a~%~}~;~]"
dd36b51b
LC
316 (length download))
317 (null? download) download))
318 (begin
319 (format (current-error-port)
83e61a73
LC
320 (N_ "~:[The following derivation will be built:~%~{ ~a~%~}~;~]"
321 "~:[The following derivations will be built:~%~{ ~a~%~}~;~]"
dd36b51b
LC
322 (length build))
323 (null? build) build)
324 (format (current-error-port)
83e61a73
LC
325 (N_ "~:[The following file will be downloaded:~%~{ ~a~%~}~;~]"
326 "~:[The following files will be downloaded:~%~{ ~a~%~}~;~]"
dd36b51b
LC
327 (length download))
328 (null? download) download)))
329 (pair? build)))
9bb2b96a 330
073c34d7
LC
331(define-syntax with-error-handling
332 (syntax-rules ()
333 "Run BODY within a user-friendly error condition handler."
334 ((_ body ...)
335 (call-with-error-handling
336 (lambda ()
337 body ...)))))
338
64fc89b6
LC
339(define (location->string loc)
340 "Return a human-friendly, GNU-standard representation of LOC."
341 (match loc
342 (#f (_ "<unknown location>"))
343 (($ <location> file line column)
344 (format #f "~a:~a:~a" file line column))))
345
c61b026e
LC
346(define (switch-symlinks link target)
347 "Atomically switch LINK, a symbolic link, to point to TARGET. Works
348both when LINK already exists and when it does not."
349 (let ((pivot (string-append link ".new")))
350 (symlink target pivot)
351 (rename-file pivot link)))
352
f651b477
LC
353(define (config-directory)
354 "Return the name of the configuration directory, after making sure that it
355exists. Honor the XDG specs,
356<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>."
357 (let ((dir (and=> (or (getenv "XDG_CONFIG_HOME")
358 (and=> (getenv "HOME")
359 (cut string-append <> "/.config")))
360 (cut string-append <> "/guix"))))
361 (catch 'system-error
362 (lambda ()
363 (mkdir dir)
364 dir)
365 (lambda args
366 (match (system-error-errno args)
367 ((or EEXIST 0)
368 dir)
369 (err
370 (leave (_ "failed to create configuration directory `~a': ~a~%")
371 dir (strerror err))))))))
372
299112d3
LC
373(define* (fill-paragraph str width #:optional (column 0))
374 "Fill STR such that each line contains at most WIDTH characters, assuming
375that the first character is at COLUMN.
376
377When STR contains a single line break surrounded by other characters, it is
378converted to a space; sequences of more than one line break are preserved."
379 (define (maybe-break chr result)
380 (match result
381 ((column newlines chars)
382 (case chr
383 ((#\newline)
384 `(,column ,(+ 1 newlines) ,chars))
385 (else
386 (let ((chars (case newlines
387 ((0) chars)
388 ((1) (cons #\space chars))
389 (else
390 (append (make-list newlines #\newline) chars))))
391 (column (case newlines
392 ((0) column)
393 ((1) (+ 1 column))
394 (else 0))))
395 (let ((chars (cons chr chars))
396 (column (+ 1 column)))
397 (if (> column width)
398 (let*-values (((before after)
399 (break (cut eqv? #\space <>) chars))
400 ((len)
401 (length before)))
402 (if (<= len width)
403 `(,len
404 0
405 ,(if (null? after)
406 before
407 (append before (cons #\newline (cdr after)))))
408 `(,column 0 ,chars))) ; unbreakable
409 `(,column 0 ,chars)))))))))
410
411 (match (string-fold maybe-break
412 `(,column 0 ())
413 str)
414 ((_ _ chars)
415 (list->string (reverse chars)))))
416
2876b989
LC
417\f
418;;;
419;;; Packages.
420;;;
421
299112d3
LC
422(define (string->recutils str)
423 "Return a version of STR where newlines have been replaced by newlines
424followed by \"+ \", which makes for a valid multi-line field value in the
425`recutils' syntax."
426 (list->string
427 (string-fold-right (lambda (chr result)
428 (if (eqv? chr #\newline)
429 (cons* chr #\+ #\space result)
430 (cons chr result)))
431 '()
432 str)))
433
434(define* (package->recutils p port
435 #:optional (width (or (and=> (getenv "WIDTH")
436 string->number)
437 80)))
438 "Write to PORT a `recutils' record of package P, arranging to fit within
439WIDTH columns."
440 (define (description->recutils str)
ee764179 441 (let ((str (P_ str)))
299112d3
LC
442 (string->recutils
443 (fill-paragraph str width
444 (string-length "description: ")))))
445
446 ;; Note: Don't i18n field names so that people can post-process it.
447 (format port "name: ~a~%" (package-name p))
448 (format port "version: ~a~%" (package-version p))
449 (format port "location: ~a~%"
450 (or (and=> (package-location p) location->string)
451 (_ "unknown")))
8fa3e6b3
LC
452
453 ;; Note: Starting from version 1.6 or recutils, hyphens are not allowed in
454 ;; field identifiers.
455 (format port "homepage: ~a~%" (package-home-page p))
456
299112d3
LC
457 (format port "license: ~a~%"
458 (match (package-license p)
459 (((? license? licenses) ...)
460 (string-join (map license-name licenses)
461 ", "))
462 ((? license? license)
463 (license-name license))
464 (x
465 (_ "unknown"))))
466 (format port "synopsis: ~a~%"
467 (string-map (match-lambda
468 (#\newline #\space)
469 (chr chr))
ee764179 470 (or (and=> (package-synopsis p) P_)
299112d3
LC
471 "")))
472 (format port "description: ~a~%"
473 (and=> (package-description p) description->recutils))
474 (newline port))
475
2cd09108
NK
476(define (string->generations str)
477 "Return the list of generations matching a pattern in STR. This function
478accepts the following patterns: \"1\", \"1,2,3\", \"1..9\", \"1..\", \"..9\"."
479 (define (maybe-integer)
480 (let ((x (string->number str)))
481 (and (integer? x)
482 x)))
483
484 (define (maybe-comma-separated-integers)
485 (let ((lst (delete-duplicates
486 (map string->number
487 (string-split str #\,)))))
488 (and (every integer? lst)
489 lst)))
490
491 (cond ((maybe-integer)
492 =>
493 list)
494 ((maybe-comma-separated-integers)
495 =>
496 identity)
497 ((string-match "^([0-9]+)\\.\\.([0-9]+)$" str)
498 =>
499 (lambda (match)
500 (let ((s (string->number (match:substring match 1)))
501 (e (string->number (match:substring match 2))))
502 (and (every integer? (list s e))
503 (<= s e)
504 (iota (1+ (- e s)) s)))))
505 ((string-match "^([0-9]+)\\.\\.$" str)
506 =>
507 (lambda (match)
508 (let ((s (string->number (match:substring match 1))))
509 (and (integer? s)
510 `(>= ,s)))))
511 ((string-match "^\\.\\.([0-9]+)$" str)
512 =>
513 (lambda (match)
514 (let ((e (string->number (match:substring match 1))))
515 (and (integer? e)
516 `(<= ,e)))))
517 (else #f)))
518
519(define (string->duration str)
520 "Return the duration matching a pattern in STR. This function accepts the
521following patterns: \"1d\", \"1w\", \"1m\"."
522 (define (hours->duration hours match)
523 (make-time time-duration 0
524 (* 3600 hours (string->number (match:substring match 1)))))
525
526 (cond ((string-match "^([0-9]+)d$" str)
527 =>
528 (lambda (match)
529 (hours->duration 24 match)))
530 ((string-match "^([0-9]+)w$" str)
531 =>
532 (lambda (match)
533 (hours->duration (* 24 7) match)))
534 ((string-match "^([0-9]+)m$" str)
535 =>
536 (lambda (match)
537 (hours->duration (* 24 30) match)))
538 (else #f)))
539
2876b989
LC
540(define* (package-specification->name+version+output spec
541 #:optional (output "out"))
542 "Parse package specification SPEC and return three value: the specified
543package name, version number (or #f), and output name (or OUTPUT). SPEC may
544optionally contain a version number and an output name, as in these examples:
545
546 guile
547 guile-2.0.9
548 guile:debug
549 guile-2.0.9:debug
550"
551 (let*-values (((name sub-drv)
552 (match (string-rindex spec #\:)
553 (#f (values spec output))
554 (colon (values (substring spec 0 colon)
555 (substring spec (+ 1 colon))))))
556 ((name version)
557 (package-name->name+version name)))
558 (values name version sub-drv)))
559
560\f
561;;;
562;;; Command-line option processing.
563;;;
564
a5975ced
LC
565(define (args-fold* options unrecognized-option-proc operand-proc . seeds)
566 "A wrapper on top of `args-fold' that does proper user-facing error
567reporting."
568 (catch 'misc-error
569 (lambda ()
570 (apply args-fold options unrecognized-option-proc
571 operand-proc seeds))
572 (lambda (key proc msg args . rest)
573 ;; XXX: MSG is not i18n'd.
574 (leave (_ "invalid argument: ~a~%")
575 (apply format #f msg args)))))
576
e49951eb 577(define (show-guix-usage)
e49951eb 578 (format (current-error-port)
25c93676
LC
579 (_ "Try `guix --help' for more information.~%"))
580 (exit 1))
e49951eb 581
e31ff8b8
LC
582(define (command-files)
583 "Return the list of source files that define Guix sub-commands."
584 (define directory
585 (and=> (search-path %load-path "guix.scm")
586 (compose (cut string-append <> "/guix/scripts")
587 dirname)))
588
2b8cf44f
LC
589 (define dot-scm?
590 (cut string-suffix? ".scm" <>))
591
592 ;; In Guile 2.0.5 `scandir' would return "." and ".." regardless even though
593 ;; they don't match `dot-scm?'. Work around it by doing additional
594 ;; filtering.
e31ff8b8 595 (if directory
2b8cf44f 596 (filter dot-scm? (scandir directory dot-scm?))
e31ff8b8
LC
597 '()))
598
599(define (commands)
600 "Return the list of Guix command names."
601 (map (compose (cut string-drop-right <> 4)
602 basename)
603 (command-files)))
604
605(define (show-guix-help)
59f734f3 606 (define (internal? command)
49e6291a 607 (member command '("substitute-binary" "authenticate" "offload")))
59f734f3 608
e31ff8b8
LC
609 (format #t (_ "Usage: guix COMMAND ARGS...
610Run COMMAND with ARGS.\n"))
611 (newline)
612 (format #t (_ "COMMAND must be one of the sub-commands listed below:\n"))
613 (newline)
614 ;; TODO: Display a synopsis of each command.
59f734f3
LC
615 (format #t "~{ ~a~%~}" (sort (remove internal? (commands))
616 string<?))
e31ff8b8
LC
617 (show-bug-report-information))
618
a2011be5
LC
619(define program-name
620 ;; Name of the command-line program currently executing, or #f.
621 (make-parameter #f))
622
ec5d0a85
LC
623(define (run-guix-command command . args)
624 "Run COMMAND with the given ARGS. Report an error when COMMAND is not
625found."
626 (define module
627 (catch 'misc-error
628 (lambda ()
629 (resolve-interface `(guix scripts ,command)))
630 (lambda -
25c93676
LC
631 (format (current-error-port)
632 (_ "guix: ~a: command not found~%") command)
633 (show-guix-usage))))
ec5d0a85
LC
634
635 (let ((command-main (module-ref module
636 (symbol-append 'guix- command))))
637 (parameterize ((program-name command))
638 (apply command-main args))))
639
a2011be5
LC
640(define guix-warning-port
641 (make-parameter (current-warning-port)))
642
e49951eb
MW
643(define (guix-main arg0 . args)
644 (initialize-guix)
645 (let ()
646 (define (option? str) (string-prefix? "-" str))
647 (match args
25c93676
LC
648 (()
649 (format (current-error-port)
650 (_ "guix: missing command name~%"))
651 (show-guix-usage))
e12b3eb9 652 ((or ("-h") ("--help"))
25c93676
LC
653 (show-guix-help))
654 (("--version")
655 (show-version-and-exit "guix"))
656 (((? option? o) args ...)
657 (format (current-error-port)
658 (_ "guix: unrecognized option '~a'~%") o)
659 (show-guix-usage))
e49951eb 660 ((command args ...)
ec5d0a85
LC
661 (apply run-guix-command
662 (string->symbol command)
663 args)))))
e49951eb 664
073c34d7 665;;; ui.scm ends here