elpa.scm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
  3. ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
  4. ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
  5. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (guix scripts import elpa)
  22. #:use-module (guix ui)
  23. #:use-module (guix utils)
  24. #:use-module (guix scripts)
  25. #:use-module (guix import elpa)
  26. #:use-module (guix import utils)
  27. #:use-module (guix scripts import)
  28. #:use-module (srfi srfi-1)
  29. #:use-module (srfi srfi-11)
  30. #:use-module (srfi srfi-37)
  31. #:use-module (ice-9 match)
  32. #:use-module (ice-9 format)
  33. #:export (guix-import-elpa))
  34. ;;;
  35. ;;; Command-line options.
  36. ;;;
  37. (define %default-options
  38. '((repo . gnu)))
  39. (define (show-help)
  40. (display (G_ "Usage: guix import elpa PACKAGE-NAME
  41. Import the latest package named PACKAGE-NAME from an ELPA repository.\n"))
  42. (display (G_ "
  43. -a, --archive=ARCHIVE specify the archive repository"))
  44. (display (G_ "
  45. -h, --help display this help and exit"))
  46. (display (G_ "
  47. -r, --recursive generate package expressions for all Emacs packages that are not yet in Guix"))
  48. (display (G_ "
  49. -V, --version display version information and exit"))
  50. (newline)
  51. (show-bug-report-information))
  52. (define %options
  53. ;; Specification of the command-line options.
  54. (cons* (option '(#\h "help") #f #f
  55. (lambda args
  56. (show-help)
  57. (exit 0)))
  58. (option '(#\V "version") #f #f
  59. (lambda args
  60. (show-version-and-exit "guix import elpa")))
  61. (option '(#\a "archive") #t #f
  62. (lambda (opt name arg result)
  63. (alist-cons 'repo (string->symbol arg)
  64. (alist-delete 'repo result))))
  65. (option '(#\r "recursive") #f #f
  66. (lambda (opt name arg result)
  67. (alist-cons 'recursive #t result)))
  68. %standard-import-options))
  69. ;;;
  70. ;;; Entry point.
  71. ;;;
  72. (define (guix-import-elpa . args)
  73. (define (parse-options)
  74. ;; Return the alist of option values.
  75. (parse-command-line args %options (list %default-options)
  76. #:build-options? #f))
  77. (let* ((opts (parse-options))
  78. (args (filter-map (match-lambda
  79. (('argument . value)
  80. value)
  81. (_ #f))
  82. (reverse opts))))
  83. (match args
  84. ((package-name)
  85. (if (assoc-ref opts 'recursive)
  86. (with-error-handling
  87. (map (match-lambda
  88. ((and ('package ('name name) . rest) pkg)
  89. `(define-public ,(string->symbol name)
  90. ,pkg))
  91. (_ #f))
  92. (elpa-recursive-import package-name
  93. (or (assoc-ref opts 'repo) 'gnu))))
  94. (let ((sexp (elpa->guix-package package-name
  95. #:repo (assoc-ref opts 'repo))))
  96. (unless sexp
  97. (leave (G_ "failed to download package '~a'~%") package-name))
  98. sexp)))
  99. (()
  100. (leave (G_ "too few arguments~%")))
  101. ((many ...)
  102. (leave (G_ "too many arguments~%"))))))
  103. ;;; elpa.scm ends here