ui: Rename '_' to 'G_'.
[jackhill/guix/guix.git] / guix / scripts / import / elpa.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
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 elpa)
20 #:use-module (guix ui)
21 #:use-module (guix utils)
22 #:use-module (guix scripts)
23 #:use-module (guix import elpa)
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-elpa))
31
32 \f
33 ;;;
34 ;;; Command-line options.
35 ;;;
36
37 (define %default-options
38 '((repo . gnu)))
39
40 (define (show-help)
41 (display (G_ "Usage: guix import elpa PACKAGE-NAME
42 Import the latest package named PACKAGE-NAME from an ELPA repository.\n"))
43 (display (G_ "
44 -a, --archive=ARCHIVE specify the archive repository"))
45 (display (G_ "
46 -h, --help display this help and exit"))
47 (display (G_ "
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 elpa")))
61 (option '(#\a "archive") #t #f
62 (lambda (opt name arg result)
63 (alist-cons 'repo (string->symbol arg)
64 (alist-delete 'repo result))))
65 %standard-import-options))
66
67 \f
68 ;;;
69 ;;; Entry point.
70 ;;;
71
72 (define (guix-import-elpa . args)
73 (define (parse-options)
74 ;; Return the alist of option values.
75 (args-fold* args %options
76 (lambda (opt name arg result)
77 (leave (G_ "~A: unrecognized option~%") name))
78 (lambda (arg result)
79 (alist-cons 'argument arg result))
80 %default-options))
81
82 (let* ((opts (parse-options))
83 (args (filter-map (match-lambda
84 (('argument . value)
85 value)
86 (_ #f))
87 (reverse opts))))
88 (match args
89 ((package-name)
90 (let ((sexp (elpa->guix-package package-name (assoc-ref opts 'repo))))
91 (unless sexp
92 (leave (G_ "failed to download package '~a'~%") package-name))
93 sexp))
94 (()
95 (leave (G_ "too few arguments~%")))
96 ((many ...)
97 (leave (G_ "too many arguments~%"))))))
98
99 ;;; elpa.scm ends here