1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
4 ;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (guix scripts import)
22 #:use-module (guix ui)
23 #:use-module (guix utils)
24 #:use-module (srfi srfi-1)
25 #:use-module (srfi srfi-11)
26 #:use-module (srfi srfi-26)
27 #:use-module (srfi srfi-37)
28 #:use-module (ice-9 format)
29 #:use-module (ice-9 match)
30 #:use-module (ice-9 pretty-print)
31 #:export (%standard-import-options
39 (define (newline-rewriting-port output)
40 "Return an output port that rewrites strings containing the \\n escape
41 to an actual newline. This works around the behavior of `pretty-print'
42 and `write', which output these as \\n instead of actual newlines,
43 whereas we want the `description' field to contain actual newlines
45 (define (write-string str)
46 (let loop ((chars (string->list str)))
54 (write-char chr output)
57 (make-soft-port (vector (cut write-char <>)
67 ;;; Command line options.
70 (define %standard-import-options '())
77 (define importers '("gnu" "nix" "pypi" "cpan" "hackage" "stackage" "elpa" "gem"
78 "cran" "crate" "texlive" "json" "opam"))
80 (define (resolve-importer name)
81 (let ((module (resolve-interface
82 `(guix scripts import ,(string->symbol name))))
83 (proc (string->symbol (string-append "guix-import-" name))))
84 (module-ref module proc)))
87 (display (G_ "Usage: guix import IMPORTER ARGS ...
88 Run IMPORTER with ARGS.\n"))
90 (display (G_ "IMPORTER must be one of the importers listed below:\n"))
92 (format #t "~{ ~a~%~}" importers)
94 -h, --help display this help and exit"))
96 -V, --version display version information and exit"))
98 (show-bug-report-information))
100 (define (guix-import . args)
103 (format (current-error-port)
104 (G_ "guix import: missing importer name~%")))
105 ((or ("-h") ("--help"))
108 ((or ("-V") ("--version"))
109 (show-version-and-exit "guix import"))
111 (if (member importer importers)
112 (let ((print (lambda (expr)
113 (pretty-print expr (newline-rewriting-port
114 (current-output-port))))))
115 (match (apply (resolve-importer importer) args)
116 ((and expr ('package _ ...))
118 ((? list? expressions)
119 (for-each (lambda (expr)
124 (leave (G_ "'~a' import failed~%") importer))))
125 (leave (G_ "~a: invalid importer~%") importer)))))