elpa.scm 3.9 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. ;;;
  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 import elpa)
  20. #:use-module (guix ui)
  21. #:use-module (guix utils)
  22. #:use-module (guix scripts)
  23. #:use-module (guix import elpa)
  24. #:use-module (guix import utils)
  25. #:use-module (guix scripts import)
  26. #:use-module (srfi srfi-1)
  27. #:use-module (srfi srfi-11)
  28. #:use-module (srfi srfi-37)
  29. #:use-module (ice-9 match)
  30. #:use-module (ice-9 format)
  31. #:export (guix-import-elpa))
  32. ;;;
  33. ;;; Command-line options.
  34. ;;;
  35. (define %default-options
  36. '((repo . gnu)))
  37. (define (show-help)
  38. (display (G_ "Usage: guix import elpa PACKAGE-NAME
  39. Import the latest package named PACKAGE-NAME from an ELPA repository.\n"))
  40. (display (G_ "
  41. -a, --archive=ARCHIVE specify the archive repository"))
  42. (display (G_ "
  43. -h, --help display this help and exit"))
  44. (display (G_ "
  45. -r, --recursive generate package expressions for all Emacs packages that are not yet in Guix"))
  46. (display (G_ "
  47. -V, --version display version information and exit"))
  48. (newline)
  49. (show-bug-report-information))
  50. (define %options
  51. ;; Specification of the command-line options.
  52. (cons* (option '(#\h "help") #f #f
  53. (lambda args
  54. (show-help)
  55. (exit 0)))
  56. (option '(#\V "version") #f #f
  57. (lambda args
  58. (show-version-and-exit "guix import elpa")))
  59. (option '(#\a "archive") #t #f
  60. (lambda (opt name arg result)
  61. (alist-cons 'repo (string->symbol arg)
  62. (alist-delete 'repo result))))
  63. (option '(#\r "recursive") #f #f
  64. (lambda (opt name arg result)
  65. (alist-cons 'recursive #t result)))
  66. %standard-import-options))
  67. ;;;
  68. ;;; Entry point.
  69. ;;;
  70. (define (guix-import-elpa . args)
  71. (define (parse-options)
  72. ;; Return the alist of option values.
  73. (args-fold* args %options
  74. (lambda (opt name arg result)
  75. (leave (G_ "~A: unrecognized option~%") name))
  76. (lambda (arg result)
  77. (alist-cons 'argument arg result))
  78. %default-options))
  79. (let* ((opts (parse-options))
  80. (args (filter-map (match-lambda
  81. (('argument . value)
  82. value)
  83. (_ #f))
  84. (reverse opts))))
  85. (match args
  86. ((package-name)
  87. (if (assoc-ref opts 'recursive)
  88. (map (match-lambda
  89. ((and ('package ('name name) . rest) pkg)
  90. `(define-public ,(string->symbol name)
  91. ,pkg))
  92. (_ #f))
  93. (elpa-recursive-import package-name
  94. (or (assoc-ref opts 'repo) 'gnu)))
  95. (let ((sexp (elpa->guix-package package-name (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