Commit | Line | Data |
---|---|---|
3e0c0365 DC |
1 | |
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 | ;;; | |
6 | ;;; This file is part of GNU Guix. | |
7 | ;;; | |
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. | |
12 | ;;; | |
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. | |
17 | ;;; | |
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/>. | |
20 | ||
21 | (define-module (guix scripts import crate) | |
22 | #:use-module (guix ui) | |
23 | #:use-module (guix utils) | |
24 | #:use-module (guix scripts) | |
25 | #:use-module (guix import crate) | |
26 | #:use-module (guix scripts import) | |
27 | #:use-module (srfi srfi-1) | |
28 | #:use-module (srfi srfi-11) | |
29 | #:use-module (srfi srfi-37) | |
30 | #:use-module (ice-9 match) | |
31 | #:use-module (ice-9 format) | |
32 | #:export (guix-import-crate)) | |
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 crate PACKAGE-NAME |
3e0c0365 | 44 | Import and convert the crate.io package for PACKAGE-NAME.\n")) |
69daee23 | 45 | (display (G_ " |
3e0c0365 | 46 | -h, --help display this help and exit")) |
69daee23 | 47 | (display (G_ " |
3e0c0365 DC |
48 | -V, --version display version information and exit")) |
49 | (newline) | |
50 | (show-bug-report-information)) | |
51 | ||
52 | (define %options | |
53 | ;; Specification of the command-line options. | |
54 | (cons* (option '(#\h "help") #f #f | |
55 | (lambda args | |
56 | (show-help) | |
57 | (exit 0))) | |
58 | (option '(#\V "version") #f #f | |
59 | (lambda args | |
60 | (show-version-and-exit "guix import crate"))) | |
61 | %standard-import-options)) | |
62 | ||
63 | \f | |
64 | ;;; | |
65 | ;;; Entry point. | |
66 | ;;; | |
67 | ||
68 | (define (guix-import-crate . args) | |
69 | (define (parse-options) | |
70 | ;; Return the alist of option values. | |
71 | (args-fold* args %options | |
72 | (lambda (opt name arg result) | |
69daee23 | 73 | (leave (G_ "~A: unrecognized option~%") name)) |
3e0c0365 DC |
74 | (lambda (arg result) |
75 | (alist-cons 'argument arg result)) | |
76 | %default-options)) | |
77 | ||
78 | (let* ((opts (parse-options)) | |
79 | (args (filter-map (match-lambda | |
80 | (('argument . value) | |
81 | value) | |
82 | (_ #f)) | |
83 | (reverse opts)))) | |
84 | (match args | |
85 | ((package-name) | |
86 | (let ((sexp (crate->guix-package package-name))) | |
87 | (unless sexp | |
69daee23 | 88 | (leave (G_ "failed to download meta-data for package '~a'~%") |
3e0c0365 DC |
89 | package-name)) |
90 | sexp)) | |
91 | (() | |
69daee23 | 92 | (leave (G_ "too few arguments~%"))) |
3e0c0365 | 93 | ((many ...) |
69daee23 | 94 | (leave (G_ "too many arguments~%")))))) |