guix-package: Add '--search'.
* guix-package.in (find-packages-by-description): New procedure. (show-help, %options): Add '--search'. (guix-package)[process-query]: Add support for '--search'. * doc/guix.texi (Invoking guix-package): Document it. * tests/guix-package.sh: Add tests.
This commit is contained in:
parent
c9ee048595
commit
acc084669c
|
@ -23,6 +23,7 @@
|
||||||
@title{GNU Guix Reference Manual}
|
@title{GNU Guix Reference Manual}
|
||||||
@subtitle{Using the GNU Guix Functional Package Manager}
|
@subtitle{Using the GNU Guix Functional Package Manager}
|
||||||
@author Ludovic Courtès
|
@author Ludovic Courtès
|
||||||
|
@author Nikita Karetnikov
|
||||||
|
|
||||||
@page
|
@page
|
||||||
@vskip 0pt plus 1filll
|
@vskip 0pt plus 1filll
|
||||||
|
@ -542,6 +543,14 @@ availability of packages:
|
||||||
|
|
||||||
@table @option
|
@table @option
|
||||||
|
|
||||||
|
@item --search=@var{regexp}
|
||||||
|
@itemx -s @var{regexp}
|
||||||
|
List the available packages whose synopsis or description matches
|
||||||
|
@var{regexp}.
|
||||||
|
|
||||||
|
For each package, print the following items, separated by tabs: its
|
||||||
|
name, version, and the source location of its definition.
|
||||||
|
|
||||||
@item --list-installed[=@var{regexp}]
|
@item --list-installed[=@var{regexp}]
|
||||||
@itemx -I [@var{regexp}]
|
@itemx -I [@var{regexp}]
|
||||||
List currently installed packages in the specified profile. When
|
List currently installed packages in the specified profile. When
|
||||||
|
|
|
@ -235,6 +235,31 @@ both when LINK already exists and when it does not."
|
||||||
(switch-link)))
|
(switch-link)))
|
||||||
(else (switch-link))))) ; anything else
|
(else (switch-link))))) ; anything else
|
||||||
|
|
||||||
|
(define (find-packages-by-description rx)
|
||||||
|
"Search in SYNOPSIS and DESCRIPTION using RX. Return a list of
|
||||||
|
matching packages."
|
||||||
|
(define (same-location? p1 p2)
|
||||||
|
;; Compare locations of two packages.
|
||||||
|
(equal? (package-location p1) (package-location p2)))
|
||||||
|
|
||||||
|
(delete-duplicates
|
||||||
|
(sort
|
||||||
|
(fold-packages (lambda (package result)
|
||||||
|
(define matches?
|
||||||
|
(cut regexp-exec rx <>))
|
||||||
|
|
||||||
|
(if (or (and=> (package-synopsis package)
|
||||||
|
(compose matches? gettext))
|
||||||
|
(and=> (package-description package)
|
||||||
|
(compose matches? gettext)))
|
||||||
|
(cons package result)
|
||||||
|
result))
|
||||||
|
'())
|
||||||
|
(lambda (p1 p2)
|
||||||
|
(string<? (package-name p1)
|
||||||
|
(package-name p2))))
|
||||||
|
same-location?))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; Command-line options.
|
;;; Command-line options.
|
||||||
|
@ -266,6 +291,8 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
|
||||||
--verbose produce verbose output"))
|
--verbose produce verbose output"))
|
||||||
(newline)
|
(newline)
|
||||||
(display (_ "
|
(display (_ "
|
||||||
|
-s, --search=REGEXP search in synopsis and description using REGEXP"))
|
||||||
|
(display (_ "
|
||||||
-I, --list-installed[=REGEXP]
|
-I, --list-installed[=REGEXP]
|
||||||
list installed packages matching REGEXP"))
|
list installed packages matching REGEXP"))
|
||||||
(display (_ "
|
(display (_ "
|
||||||
|
@ -311,6 +338,10 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
|
||||||
(option '("verbose") #f #f
|
(option '("verbose") #f #f
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(alist-cons 'verbose? #t result)))
|
(alist-cons 'verbose? #t result)))
|
||||||
|
(option '(#\s "search") #t #f
|
||||||
|
(lambda (opt name arg result)
|
||||||
|
(cons `(query search ,(or arg ""))
|
||||||
|
result)))
|
||||||
(option '(#\I "list-installed") #f #t
|
(option '(#\I "list-installed") #f #t
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(cons `(query list-installed ,(or arg ""))
|
(cons `(query list-installed ,(or arg ""))
|
||||||
|
@ -532,6 +563,7 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
|
||||||
name (or version "?") output path))))
|
name (or version "?") output path))))
|
||||||
installed)
|
installed)
|
||||||
#t))
|
#t))
|
||||||
|
|
||||||
(('list-available regexp)
|
(('list-available regexp)
|
||||||
(let* ((regexp (and regexp (make-regexp regexp)))
|
(let* ((regexp (and regexp (make-regexp regexp)))
|
||||||
(available (fold-packages
|
(available (fold-packages
|
||||||
|
@ -554,6 +586,16 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
|
||||||
(string<? (package-name p1)
|
(string<? (package-name p1)
|
||||||
(package-name p2)))))
|
(package-name p2)))))
|
||||||
#t))
|
#t))
|
||||||
|
|
||||||
|
(('search regexp)
|
||||||
|
(let ((regexp (and regexp (make-regexp regexp))))
|
||||||
|
(for-each (lambda (p)
|
||||||
|
(format #t "~a\t~a\t~a~%"
|
||||||
|
(package-name p)
|
||||||
|
(package-version p)
|
||||||
|
(location->string (package-location p))))
|
||||||
|
(find-packages-by-description regexp))
|
||||||
|
#t))
|
||||||
(_ #f))))
|
(_ #f))))
|
||||||
|
|
||||||
(setlocale LC_ALL "")
|
(setlocale LC_ALL "")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# GNU Guix --- Functional package management for GNU
|
# GNU Guix --- Functional package management for GNU
|
||||||
# Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
|
# Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
|
||||||
|
# Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
|
||||||
#
|
#
|
||||||
# This file is part of GNU Guix.
|
# This file is part of GNU Guix.
|
||||||
#
|
#
|
||||||
|
@ -68,6 +69,10 @@ then
|
||||||
|
|
||||||
test "`guix-package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
|
test "`guix-package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
|
||||||
|
|
||||||
|
# Search.
|
||||||
|
test "`guix-package -s "GNU Hello" | cut -f1`" = "hello"
|
||||||
|
test "`guix-package -s "n0t4r341p4ck4g3"`" = ""
|
||||||
|
|
||||||
# Remove a package.
|
# Remove a package.
|
||||||
guix-package --bootstrap -p "$profile" -r "guile-bootstrap"
|
guix-package --bootstrap -p "$profile" -r "guile-bootstrap"
|
||||||
test -L "$profile-3-link"
|
test -L "$profile-3-link"
|
||||||
|
|
Loading…
Reference in New Issue