Commit | Line | Data |
---|---|---|
e1248602 RW |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org> | |
1a75083b | 3 | ;;; Copyright © 2015, 2017 Ricardo Wurmus <rekado@elephly.net> |
e1248602 RW |
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 | ||
20 | (define-module (guix scripts import cran) | |
21 | #:use-module (guix ui) | |
22 | #:use-module (guix utils) | |
88981dd3 | 23 | #:use-module (guix scripts) |
e1248602 RW |
24 | #:use-module (guix import cran) |
25 | #:use-module (guix scripts import) | |
26 | #:use-module (srfi srfi-1) | |
27 | #:use-module (srfi srfi-11) | |
28 | #:use-module (srfi srfi-37) | |
64ce53eb | 29 | #:use-module (srfi srfi-41) |
e1248602 RW |
30 | #:use-module (ice-9 match) |
31 | #:use-module (ice-9 format) | |
32 | #:export (guix-import-cran)) | |
33 | ||
34 | \f | |
35 | ;;; | |
36 | ;;; Command-line options. | |
37 | ;;; | |
38 | ||
39 | (define %default-options | |
40 | '()) | |
41 | ||
42 | (define (show-help) | |
69daee23 | 43 | (display (G_ "Usage: guix import cran PACKAGE-NAME |
e1248602 | 44 | Import and convert the CRAN package for PACKAGE-NAME.\n")) |
69daee23 | 45 | (display (G_ " |
d0bd632f | 46 | -a, --archive=ARCHIVE specify the archive repository")) |
69daee23 | 47 | (display (G_ " |
e1248602 | 48 | -h, --help display this help and exit")) |
69daee23 | 49 | (display (G_ " |
e1248602 RW |
50 | -V, --version display version information and exit")) |
51 | (newline) | |
52 | (show-bug-report-information)) | |
53 | ||
54 | (define %options | |
55 | ;; Specification of the command-line options. | |
56 | (cons* (option '(#\h "help") #f #f | |
57 | (lambda args | |
58 | (show-help) | |
59 | (exit 0))) | |
60 | (option '(#\V "version") #f #f | |
61 | (lambda args | |
62 | (show-version-and-exit "guix import cran"))) | |
d0bd632f RW |
63 | (option '(#\a "archive") #t #f |
64 | (lambda (opt name arg result) | |
65 | (alist-cons 'repo (string->symbol arg) | |
66 | (alist-delete 'repo result)))) | |
64ce53eb RW |
67 | (option '(#\r "recursive") #f #f |
68 | (lambda (opt name arg result) | |
69 | (alist-cons 'recursive #t result))) | |
e1248602 RW |
70 | %standard-import-options)) |
71 | ||
72 | \f | |
73 | ;;; | |
74 | ;;; Entry point. | |
75 | ;;; | |
76 | ||
77 | (define (guix-import-cran . args) | |
78 | (define (parse-options) | |
79 | ;; Return the alist of option values. | |
80 | (args-fold* args %options | |
81 | (lambda (opt name arg result) | |
69daee23 | 82 | (leave (G_ "~A: unrecognized option~%") name)) |
e1248602 RW |
83 | (lambda (arg result) |
84 | (alist-cons 'argument arg result)) | |
85 | %default-options)) | |
86 | ||
87 | (let* ((opts (parse-options)) | |
88 | (args (filter-map (match-lambda | |
89 | (('argument . value) | |
90 | value) | |
91 | (_ #f)) | |
92 | (reverse opts)))) | |
93 | (match args | |
94 | ((package-name) | |
64ce53eb RW |
95 | (if (assoc-ref opts 'recursive) |
96 | ;; Recursive import | |
97 | (map (match-lambda | |
98 | ((and ('package ('name name) . rest) pkg) | |
99 | `(define-public ,(string->symbol name) | |
100 | ,pkg)) | |
101 | (_ #f)) | |
1a75083b RW |
102 | (reverse (stream->list (recursive-import package-name |
103 | (or (assoc-ref opts 'repo) 'cran))))) | |
64ce53eb RW |
104 | ;; Single import |
105 | (let ((sexp (cran->guix-package package-name | |
106 | (or (assoc-ref opts 'repo) 'cran)))) | |
107 | (unless sexp | |
69daee23 | 108 | (leave (G_ "failed to download description for package '~a'~%") |
64ce53eb RW |
109 | package-name)) |
110 | sexp))) | |
e1248602 | 111 | (() |
69daee23 | 112 | (leave (G_ "too few arguments~%"))) |
e1248602 | 113 | ((many ...) |
69daee23 | 114 | (leave (G_ "too many arguments~%")))))) |