upgrade.scm 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. (define-module (guix scripts upgrade)
  19. #:use-module (guix ui)
  20. #:use-module (guix scripts package)
  21. #:use-module (guix scripts build)
  22. #:use-module (guix scripts)
  23. #:use-module (srfi srfi-1)
  24. #:use-module (srfi srfi-26)
  25. #:use-module (srfi srfi-37)
  26. #:use-module (ice-9 match)
  27. #:export (guix-upgrade))
  28. (define (show-help)
  29. (display (G_ "Usage: guix upgrade [OPTION] [REGEXP]
  30. Upgrade packages that match REGEXP.
  31. This is an alias for 'guix package -u'.\n"))
  32. (display (G_ "
  33. -p, --profile=PROFILE use PROFILE instead of the user's default profile"))
  34. (display (G_ "
  35. -v, --verbosity=LEVEL use the given verbosity LEVEL"))
  36. (newline)
  37. (show-build-options-help)
  38. (newline)
  39. (show-transformation-options-help)
  40. (newline)
  41. (display (G_ "
  42. -h, --help display this help and exit"))
  43. (display (G_ "
  44. -V, --version display version information and exit"))
  45. (newline)
  46. (show-bug-report-information))
  47. (define %options
  48. ;; Specification of the command-line options.
  49. (cons* (option '(#\h "help") #f #f
  50. (lambda args
  51. (show-help)
  52. (exit 0)))
  53. (option '(#\V "version") #f #f
  54. (lambda args
  55. (show-version-and-exit "guix upgrade")))
  56. ;; Preserve some of the 'guix package' options.
  57. (append (filter (lambda (option)
  58. (any (cut member <> (option-names option))
  59. '("profile" "dry-run" "verbosity")))
  60. %package-options)
  61. %transformation-options
  62. %standard-build-options)))
  63. (define (guix-upgrade . args)
  64. (define (handle-argument arg result arg-handler)
  65. ;; Accept at most one non-option argument, and treat it as an upgrade
  66. ;; regexp.
  67. (match (assq-ref result 'upgrade)
  68. (#f
  69. (values (alist-cons 'upgrade arg
  70. (alist-delete 'upgrade result))
  71. arg-handler))
  72. (_
  73. (leave (G_ "~A: extraneous argument~%") arg))))
  74. (define opts
  75. (parse-command-line args %options
  76. (list `((upgrade . #f)
  77. ,@%package-default-options)
  78. #f)
  79. #:argument-handler handle-argument))
  80. (guix-package* opts))