edit.scm 2.8 KB

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