search.scm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
  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. (define-module (guix scripts search)
  20. #:use-module (guix ui)
  21. #:use-module (guix scripts package)
  22. #:use-module ((guix scripts build)
  23. #:select (%standard-build-options))
  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. (define (show-help)
  30. (display (G_ "Usage: guix search [OPTION] REGEXPS...
  31. Search for packages matching REGEXPS."))
  32. (display (G_"
  33. This is an alias for 'guix package -s'.\n"))
  34. (newline)
  35. (display (G_ "
  36. -h, --help display this help and exit"))
  37. (display (G_ "
  38. -V, --version display version information and exit"))
  39. (newline)
  40. (display (G_ "
  41. -L, --load-path=DIR prepend DIR to the package module search path"))
  42. (newline)
  43. (show-bug-report-information))
  44. (define %options
  45. ;; Specification of the command-line options.
  46. (list (option '(#\h "help") #f #f
  47. (lambda args
  48. (show-help)
  49. (exit 0)))
  50. (option '(#\V "version") #f #f
  51. (lambda args
  52. (show-version-and-exit "guix search")))
  53. (find (lambda (option)
  54. (member "load-path" (option-names option)))
  55. %standard-build-options)))
  56. (define-command (guix-search . args)
  57. (synopsis "search for packages")
  58. (define (handle-argument arg result)
  59. ;; Treat all non-option arguments as regexps.
  60. (cons `(query search ,(or arg ""))
  61. result))
  62. (define opts
  63. (parse-command-line args %options (list (list))
  64. #:build-options? #f
  65. #:argument-handler handle-argument))
  66. (unless (assoc-ref opts 'query)
  67. (leave (G_ "missing arguments: no regular expressions to search for~%")))
  68. (guix-package* opts))