edit.scm 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2022, 2023 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 system edit)
  19. #:use-module (guix diagnostics)
  20. #:use-module (guix i18n)
  21. #:use-module (guix ui)
  22. #:autoload (guix utils) (string-closest)
  23. #:use-module (gnu services)
  24. #:use-module (srfi srfi-1)
  25. #:use-module (ice-9 match)
  26. #:autoload (guix scripts edit) (spawn-editor)
  27. #:export (guix-system-edit))
  28. (define (service-type-not-found type)
  29. "Report an error about @var{type} not being found and exit."
  30. (report-error (G_ "~a: no such service type~%") type)
  31. (let* ((type (symbol->string type))
  32. (available (fold-service-types (lambda (type lst)
  33. (cons (symbol->string
  34. (service-type-name type))
  35. lst))
  36. '()))
  37. (closest (string-closest type available)))
  38. (unless (or (not closest) (string=? closest type))
  39. (display-hint (G_ "Did you mean @code{~a}?~%")
  40. closest)))
  41. (exit 1))
  42. (define (guix-system-edit . args)
  43. (when (null? args)
  44. (leave (G_ "no service types specified, nothing to edit~%")))
  45. (let* ((types (append-map (lambda (type)
  46. (let ((type (string->symbol type)))
  47. (match (lookup-service-types type)
  48. (() (service-type-not-found type))
  49. ((one) (list one))
  50. (lst
  51. (warning (N_ "~a: ~a matching service type~%"
  52. "~a: ~a matching service types~%"
  53. (length lst))
  54. type (length lst))
  55. lst))))
  56. args)))
  57. (spawn-editor (filter-map service-type-location types))))