pack: Add '--entry-point'.
[jackhill/guix/guix.git] / guix / scripts / search.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
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)
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))
27
28 (define (show-help)
29 (display (G_ "Usage: guix search [OPTION] REGEXPS...
30 Search for packages matching REGEXPS."))
31 (display (G_"
32 This is an alias for 'guix package -s'.\n"))
33 (newline)
34 (display (G_ "
35 -h, --help display this help and exit"))
36 (display (G_ "
37 -V, --version display version information and exit"))
38 (newline)
39 (show-bug-report-information))
40
41 (define %options
42 ;; Specification of the command-line options.
43 (list (option '(#\h "help") #f #f
44 (lambda args
45 (show-help)
46 (exit 0)))
47 (option '(#\V "version") #f #f
48 (lambda args
49 (show-version-and-exit "guix search")))))
50
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 ""))
55 result))
56
57 (define opts
58 (args-fold* args %options
59 (lambda (opt name arg . rest)
60 (leave (G_ "~A: unrecognized option~%") name))
61 handle-argument
62 '()))
63
64 (unless (assoc-ref opts 'query)
65 (leave (G_ "missing arguments: no regular expressions to search for~%")))
66
67 (guix-package* opts))