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