crate.scm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 David Thompson <davet@gnu.org>
  3. ;;; Copyright © 2016 David Craven <david@craven.ch>
  4. ;;; Copyright © 2019, 2020 Martin Becze <mjbecze@riseup.net>
  5. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  6. ;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (guix scripts import crate)
  23. #:use-module (guix ui)
  24. #:use-module (guix utils)
  25. #:use-module (guix scripts)
  26. #:use-module (guix import crate)
  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-crate))
  34. ;;;
  35. ;;; Command-line options.
  36. ;;;
  37. (define %default-options
  38. '())
  39. (define (show-help)
  40. (display (G_ "Usage: guix import crate PACKAGE-NAME
  41. Import and convert the crates.io package for PACKAGE-NAME.\n"))
  42. (display (G_ "
  43. -r, --recursive import packages recursively"))
  44. (newline)
  45. (display (G_ "
  46. -h, --help display this help and exit"))
  47. (display (G_ "
  48. -V, --version display version information and exit"))
  49. (newline)
  50. (show-bug-report-information))
  51. (define %options
  52. ;; Specification of the command-line options.
  53. (cons* (option '(#\h "help") #f #f
  54. (lambda args
  55. (show-help)
  56. (exit 0)))
  57. (option '(#\V "version") #f #f
  58. (lambda args
  59. (show-version-and-exit "guix import crate")))
  60. (option '(#\r "recursive") #f #f
  61. (lambda (opt name arg result)
  62. (alist-cons 'recursive #t result)))
  63. %standard-import-options))
  64. ;;;
  65. ;;; Entry point.
  66. ;;;
  67. (define (guix-import-crate . args)
  68. (define (parse-options)
  69. ;; Return the alist of option values.
  70. (parse-command-line args %options (list %default-options)
  71. #:build-options? #f))
  72. (let* ((opts (parse-options))
  73. (args (filter-map (match-lambda
  74. (('argument . value)
  75. value)
  76. (_ #f))
  77. (reverse opts))))
  78. (match args
  79. ((spec)
  80. (define-values (name version)
  81. (package-name->name+version spec))
  82. (match (if (assoc-ref opts 'recursive)
  83. (crate-recursive-import name #:version version)
  84. (crate->guix-package name #:version version #:include-dev-deps? #t))
  85. ((or #f '())
  86. (leave (G_ "failed to download meta-data for package '~a'~%")
  87. (if version
  88. (string-append name "@" version)
  89. name)))
  90. ((? list? sexps) sexps)
  91. (sexp (list sexp))))
  92. (()
  93. (leave (G_ "too few arguments~%")))
  94. ((many ...)
  95. (leave (G_ "too many arguments~%"))))))