upgrade.scm 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
  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. (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. (define (show-help)
  30. (display (G_ "Usage: guix upgrade [OPTION] [REGEXP]
  31. Upgrade packages that match REGEXP.
  32. This is an alias for 'guix package -u'.\n"))
  33. (display (G_ "
  34. -p, --profile=PROFILE use PROFILE instead of the user's default profile"))
  35. (display (G_ "
  36. -v, --verbosity=LEVEL use the given verbosity LEVEL"))
  37. (newline)
  38. (show-build-options-help)
  39. (newline)
  40. (show-transformation-options-help)
  41. (newline)
  42. (display (G_ "
  43. -h, --help display this help and exit"))
  44. (display (G_ "
  45. -V, --version display version information and exit"))
  46. (newline)
  47. (show-bug-report-information))
  48. (define %options
  49. ;; Specification of the command-line options.
  50. (cons* (option '(#\h "help") #f #f
  51. (lambda args
  52. (show-help)
  53. (exit 0)))
  54. (option '(#\V "version") #f #f
  55. (lambda args
  56. (show-version-and-exit "guix upgrade")))
  57. ;; Preserve some of the 'guix package' options.
  58. (append (filter (lambda (option)
  59. (any (cut member <> (option-names option))
  60. '("profile" "dry-run" "verbosity" "do-not-upgrade")))
  61. %package-options)
  62. %transformation-options
  63. %standard-build-options)))
  64. (define-command (guix-upgrade . args)
  65. (synopsis "upgrade packages to their latest version")
  66. (define (handle-argument arg result arg-handler)
  67. ;; Accept at most one non-option argument, and treat it as an upgrade
  68. ;; regexp.
  69. (match (assq-ref result 'upgrade)
  70. (#f
  71. (values (alist-cons 'upgrade arg
  72. (alist-delete 'upgrade result))
  73. arg-handler))
  74. (_
  75. (leave (G_ "~A: extraneous argument~%") arg))))
  76. (define opts
  77. (parse-command-line args %options
  78. (list `((upgrade . #f)
  79. ,@%package-default-options)
  80. #f)
  81. #:argument-handler handle-argument))
  82. (guix-package* opts))