1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (guix scripts search)
20 #:use-module (guix ui)
21 #:use-module (guix scripts package)
22 #:use-module (guix scripts)
23 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-26)
25 #:use-module (srfi srfi-37)
26 #:export (guix-search))
29 (display (G_ "Usage: guix search [OPTION] REGEXPS...
30 Search for packages matching REGEXPS."))
32 This is an alias for 'guix package -s'.\n"))
35 -h, --help display this help and exit"))
37 -V, --version display version information and exit"))
39 (show-bug-report-information))
42 ;; Specification of the command-line options.
43 (list (option '(#\h "help") #f #f
47 (option '(#\V "version") #f #f
49 (show-version-and-exit "guix search")))))
51 (define (guix-search . args)
52 (define (handle-argument arg result)
53 ;; Treat all non-option arguments as regexps.
54 (cons `(query search ,(or arg ""))
58 (args-fold* args %options
59 (lambda (opt name arg . rest)
60 (leave (G_ "~A: unrecognized option~%") name))
64 (unless (assoc-ref opts 'query)
65 (leave (G_ "missing arguments: no regular expressions to search for~%")))