1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
3 ;;; Copyright © 2015, 2017 Ricardo Wurmus <rekado@elephly.net>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
20 (define-module (guix scripts import json)
22 #:use-module (guix ui)
23 #:use-module (guix utils)
24 #:use-module (guix scripts)
25 #:use-module (guix import utils)
26 #:use-module (guix import json)
27 #:use-module (guix scripts import)
28 #:use-module (guix packages)
29 #:use-module (srfi srfi-1)
30 #:use-module (srfi srfi-9 gnu)
31 #:use-module (srfi srfi-11)
32 #:use-module (srfi srfi-37)
33 #:use-module (srfi srfi-41)
34 #:use-module (ice-9 match)
35 #:use-module (ice-9 rdelim)
36 #:use-module (ice-9 format)
37 #:export (guix-import-json))
41 ;;; Command-line options.
44 (define %default-options
48 (display (G_ "Usage: guix import json PACKAGE-FILE
49 Import and convert the JSON package definition in PACKAGE-FILE.\n"))
51 -h, --help display this help and exit"))
53 -V, --version display version information and exit"))
55 (show-bug-report-information))
58 ;; Specification of the command-line options.
59 (cons* (option '(#\h "help") #f #f
63 (option '(#\V "version") #f #f
65 (show-version-and-exit "guix import json")))
66 %standard-import-options))
73 (define (guix-import-json . args)
74 (define (parse-options)
75 ;; Return the alist of option values.
76 (args-fold* args %options
77 (lambda (opt name arg result)
78 (leave (G_ "~A: unrecognized option~%") name))
80 (alist-cons 'argument arg result))
83 (let* ((opts (parse-options))
84 (args (filter-map (match-lambda
91 (or (json->code file-name)
92 (leave (G_ "invalid JSON in file '~a'~%") file-name)))
94 (leave (G_ "too few arguments~%")))
96 (leave (G_ "too many arguments~%"))))))