ui: Rename '_' to 'G_'.
[jackhill/guix/guix.git] / guix / scripts / import / cpan.scm
CommitLineData
d45dc6da
EB
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (guix scripts import cpan)
20 #:use-module (guix ui)
21 #:use-module (guix utils)
88981dd3 22 #:use-module (guix scripts)
d45dc6da
EB
23 #:use-module (guix import cpan)
24 #:use-module (guix scripts import)
25 #:use-module (srfi srfi-1)
26 #:use-module (srfi srfi-11)
27 #:use-module (srfi srfi-37)
28 #:use-module (ice-9 match)
29 #:use-module (ice-9 format)
30 #:export (guix-import-cpan))
31
32\f
33;;;
34;;; Command-line options.
35;;;
36
37(define %default-options
38 '())
39
40(define (show-help)
69daee23 41 (display (G_ "Usage: guix import cpan PACKAGE-NAME
d45dc6da 42Import and convert the CPAN package for PACKAGE-NAME.\n"))
69daee23 43 (display (G_ "
d45dc6da 44 -h, --help display this help and exit"))
69daee23 45 (display (G_ "
d45dc6da
EB
46 -V, --version display version information and exit"))
47 (newline)
48 (show-bug-report-information))
49
50(define %options
51 ;; Specification of the command-line options.
52 (cons* (option '(#\h "help") #f #f
53 (lambda args
54 (show-help)
55 (exit 0)))
56 (option '(#\V "version") #f #f
57 (lambda args
58 (show-version-and-exit "guix import cpan")))
59 %standard-import-options))
60
61\f
62;;;
63;;; Entry point.
64;;;
65
66(define (guix-import-cpan . args)
67 (define (parse-options)
68 ;; Return the alist of option values.
69 (args-fold* args %options
70 (lambda (opt name arg result)
69daee23 71 (leave (G_ "~A: unrecognized option~%") name))
d45dc6da
EB
72 (lambda (arg result)
73 (alist-cons 'argument arg result))
74 %default-options))
75
76 (let* ((opts (parse-options))
77 (args (filter-map (match-lambda
78 (('argument . value)
79 value)
80 (_ #f))
81 (reverse opts))))
82 (match args
83 ((package-name)
84 (let ((sexp (cpan->guix-package package-name)))
85 (unless sexp
69daee23 86 (leave (G_ "failed to download meta-data for package '~a'~%")
d45dc6da
EB
87 package-name))
88 sexp))
89 (()
69daee23 90 (leave (G_ "too few arguments~%")))
d45dc6da 91 ((many ...)
69daee23 92 (leave (G_ "too many arguments~%"))))))