Commit | Line | Data |
---|---|---|
32efa254 DT |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2015 David Thompson <davet@gnu.org> | |
7ede577a | 3 | ;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com> |
32efa254 DT |
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 container) | |
21 | #:use-module (ice-9 match) | |
22 | #:use-module (guix ui) | |
23 | #:export (guix-container)) | |
24 | ||
25 | (define (show-help) | |
69daee23 | 26 | (display (G_ "Usage: guix container ACTION ARGS... |
32efa254 DT |
27 | Build and manipulate Linux containers.\n")) |
28 | (newline) | |
69daee23 | 29 | (display (G_ "The valid values for ACTION are:\n")) |
32efa254 | 30 | (newline) |
69daee23 | 31 | (display (G_ "\ |
32efa254 DT |
32 | exec execute a command inside of an existing container\n")) |
33 | (newline) | |
69daee23 | 34 | (display (G_ " |
32efa254 | 35 | -h, --help display this help and exit")) |
69daee23 | 36 | (display (G_ " |
32efa254 DT |
37 | -V, --version display version information and exit")) |
38 | (newline) | |
39 | (show-bug-report-information)) | |
40 | ||
41 | (define %actions '("exec")) | |
42 | ||
43 | (define (resolve-action name) | |
44 | (let ((module (resolve-interface | |
45 | `(guix scripts container ,(string->symbol name)))) | |
46 | (proc (string->symbol (string-append "guix-container-" name)))) | |
47 | (module-ref module proc))) | |
48 | ||
49 | (define (guix-container . args) | |
50 | (with-error-handling | |
51 | (match args | |
52 | (() | |
53 | (format (current-error-port) | |
69daee23 | 54 | (G_ "guix container: missing action~%"))) |
32efa254 DT |
55 | ((or ("-h") ("--help")) |
56 | (show-help) | |
57 | (exit 0)) | |
7ede577a | 58 | ((or ("-V") ("--version")) |
32efa254 DT |
59 | (show-version-and-exit "guix container")) |
60 | ((action args ...) | |
61 | (if (member action %actions) | |
62 | (apply (resolve-action action) args) | |
63 | (format (current-error-port) | |
69daee23 | 64 | (G_ "guix container: invalid action~%"))))))) |