2 ;;; GNU Guix --- Functional package management for GNU
3 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
4 ;;; Copyright © 2016 David Craven <david@craven.ch>
5 ;;; Copyright © 2019 Martin Becze <mjbecze@riseup.net>
7 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
37 ;;; Command-line options.
40 (define %default-options
44 (display (G_ "Usage: guix import crate PACKAGE-NAME
45 Import and convert the crate.io package for PACKAGE-NAME.\n"))
47 -r, --recursive import packages recursively"))
50 -h, --help display this help and exit"))
52 -V, --version display version information and exit"))
54 (show-bug-report-information))
57 ;; Specification of the command-line options.
58 (cons* (option '(#\h "help") #f #f
62 (option '(#\V "version") #f #f
64 (show-version-and-exit "guix import crate")))
65 (option '(#\r "recursive") #f #f
66 (lambda (opt name arg result)
67 (alist-cons 'recursive #t result)))
68 %standard-import-options))
75 (define (guix-import-crate . args)
76 (define (parse-options)
77 ;; Return the alist of option values.
78 (args-fold* args %options
79 (lambda (opt name arg result)
80 (leave (G_ "~A: unrecognized option~%") name))
82 (alist-cons 'argument arg result))
86 (let* ((opts (parse-options))
87 (args (filter-map (match-lambda
94 (define-values (name version)
95 (package-name->name+version spec))
97 (if (assoc-ref opts 'recursive)
99 ((and ('package ('name name) . rest) pkg)
100 `(define-public ,(string->symbol name)
103 (crate-recursive-import name))
104 (let ((sexp (crate->guix-package name version)))
106 (leave (G_ "failed to download meta-data for package '~a'~%")
108 (string-append name "@" version)
112 (leave (G_ "too few arguments~%")))
114 (leave (G_ "too many arguments~%"))))))