Commit | Line | Data |
---|---|---|
da56f109 | 1 | ;;; GNU Guix --- Functional package management for GNU |
3794ce93 | 2 | ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
da56f109 LC |
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 search) | |
20 | #:use-module (guix ui) | |
21 | #:use-module (guix scripts package) | |
4f8c29a7 LC |
22 | #:use-module ((guix scripts build) |
23 | #:select (%standard-build-options)) | |
da56f109 LC |
24 | #:use-module (guix scripts) |
25 | #:use-module (srfi srfi-1) | |
26 | #:use-module (srfi srfi-26) | |
27 | #:use-module (srfi srfi-37) | |
28 | #:export (guix-search)) | |
29 | ||
30 | (define (show-help) | |
31 | (display (G_ "Usage: guix search [OPTION] REGEXPS... | |
32 | Search for packages matching REGEXPS.")) | |
33 | (display (G_" | |
34 | This is an alias for 'guix package -s'.\n")) | |
35 | (newline) | |
36 | (display (G_ " | |
37 | -h, --help display this help and exit")) | |
38 | (display (G_ " | |
39 | -V, --version display version information and exit")) | |
40 | (newline) | |
4f8c29a7 LC |
41 | (display (G_ " |
42 | -L, --load-path=DIR prepend DIR to the package module search path")) | |
43 | (newline) | |
da56f109 LC |
44 | (show-bug-report-information)) |
45 | ||
46 | (define %options | |
47 | ;; Specification of the command-line options. | |
48 | (list (option '(#\h "help") #f #f | |
49 | (lambda args | |
50 | (show-help) | |
51 | (exit 0))) | |
52 | (option '(#\V "version") #f #f | |
53 | (lambda args | |
4f8c29a7 LC |
54 | (show-version-and-exit "guix search"))) |
55 | ||
56 | (find (lambda (option) | |
57 | (member "load-path" (option-names option))) | |
58 | %standard-build-options))) | |
da56f109 | 59 | |
3794ce93 LC |
60 | (define-command (guix-search . args) |
61 | (synopsis "search for packages") | |
62 | ||
da56f109 LC |
63 | (define (handle-argument arg result) |
64 | ;; Treat all non-option arguments as regexps. | |
65 | (cons `(query search ,(or arg "")) | |
66 | result)) | |
67 | ||
68 | (define opts | |
69 | (args-fold* args %options | |
70 | (lambda (opt name arg . rest) | |
71 | (leave (G_ "~A: unrecognized option~%") name)) | |
72 | handle-argument | |
73 | '())) | |
74 | ||
75 | (unless (assoc-ref opts 'query) | |
76 | (leave (G_ "missing arguments: no regular expressions to search for~%"))) | |
77 | ||
78 | (guix-package* opts)) |