Commit | Line | Data |
---|---|---|
d824cfba | 1 | ;;; GNU Guix --- Functional package management for GNU |
3794ce93 | 2 | ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
7ba7d50f | 3 | ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net> |
d824cfba LC |
4 | ;;; |
5 | ;;; This file is part of GNU Guix. | |
6 | ;;; | |
7 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
8 | ;;; under the terms of the GNU General Public License as published by | |
9 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
10 | ;;; your option) any later version. | |
11 | ;;; | |
12 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
13 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;;; GNU General Public License for more details. | |
16 | ;;; | |
17 | ;;; You should have received a copy of the GNU General Public License | |
18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | (define-module (guix scripts upgrade) | |
21 | #:use-module (guix ui) | |
22 | #:use-module (guix scripts package) | |
23 | #:use-module (guix scripts build) | |
24 | #:use-module (guix scripts) | |
25 | #:use-module (srfi srfi-1) | |
26 | #:use-module (srfi srfi-26) | |
27 | #:use-module (srfi srfi-37) | |
28 | #:use-module (ice-9 match) | |
29 | #:export (guix-upgrade)) | |
30 | ||
31 | (define (show-help) | |
32 | (display (G_ "Usage: guix upgrade [OPTION] [REGEXP] | |
33 | Upgrade packages that match REGEXP. | |
34 | This is an alias for 'guix package -u'.\n")) | |
35 | (display (G_ " | |
36 | -p, --profile=PROFILE use PROFILE instead of the user's default profile")) | |
37 | (display (G_ " | |
38 | -v, --verbosity=LEVEL use the given verbosity LEVEL")) | |
39 | (newline) | |
40 | (show-build-options-help) | |
41 | (newline) | |
42 | (show-transformation-options-help) | |
43 | (newline) | |
44 | (display (G_ " | |
45 | -h, --help display this help and exit")) | |
46 | (display (G_ " | |
47 | -V, --version display version information and exit")) | |
48 | (newline) | |
49 | (show-bug-report-information)) | |
50 | ||
51 | (define %options | |
52 | ;; Specification of the command-line options. | |
53 | (cons* (option '(#\h "help") #f #f | |
54 | (lambda args | |
55 | (show-help) | |
56 | (exit 0))) | |
57 | (option '(#\V "version") #f #f | |
58 | (lambda args | |
59 | (show-version-and-exit "guix upgrade"))) | |
60 | ||
61 | ;; Preserve some of the 'guix package' options. | |
62 | (append (filter (lambda (option) | |
63 | (any (cut member <> (option-names option)) | |
7ba7d50f | 64 | '("profile" "dry-run" "verbosity" "do-not-upgrade"))) |
d824cfba LC |
65 | %package-options) |
66 | ||
67 | %transformation-options | |
68 | %standard-build-options))) | |
69 | ||
3794ce93 LC |
70 | (define-command (guix-upgrade . args) |
71 | (synopsis "upgrade packages to their latest version") | |
72 | ||
d824cfba LC |
73 | (define (handle-argument arg result arg-handler) |
74 | ;; Accept at most one non-option argument, and treat it as an upgrade | |
75 | ;; regexp. | |
76 | (match (assq-ref result 'upgrade) | |
77 | (#f | |
78 | (values (alist-cons 'upgrade arg | |
79 | (alist-delete 'upgrade result)) | |
80 | arg-handler)) | |
81 | (_ | |
82 | (leave (G_ "~A: extraneous argument~%") arg)))) | |
83 | ||
84 | (define opts | |
85 | (parse-command-line args %options | |
86 | (list `((upgrade . #f) | |
87 | ,@%package-default-options) | |
88 | #f) | |
89 | #:argument-handler handle-argument)) | |
90 | ||
91 | (guix-package* opts)) |