search.scm 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019, 2020 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. (define-module (guix scripts search)
  19. #:use-module (guix ui)
  20. #:use-module (guix scripts package)
  21. #:use-module ((guix scripts build)
  22. #:select (%standard-build-options))
  23. #:use-module (guix scripts)
  24. #:use-module (srfi srfi-1)
  25. #:use-module (srfi srfi-26)
  26. #:use-module (srfi srfi-37)
  27. #:export (guix-search))
  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. (display (G_ "
  40. -L, --load-path=DIR prepend DIR to the package module search path"))
  41. (newline)
  42. (show-bug-report-information))
  43. (define %options
  44. ;; Specification of the command-line options.
  45. (list (option '(#\h "help") #f #f
  46. (lambda args
  47. (show-help)
  48. (exit 0)))
  49. (option '(#\V "version") #f #f
  50. (lambda args
  51. (show-version-and-exit "guix search")))
  52. (find (lambda (option)
  53. (member "load-path" (option-names option)))
  54. %standard-build-options)))
  55. (define-command (guix-search . args)
  56. (synopsis "search for packages")
  57. (define (handle-argument arg result)
  58. ;; Treat all non-option arguments as regexps.
  59. (cons `(query search ,(or arg ""))
  60. result))
  61. (define opts
  62. (args-fold* args %options
  63. (lambda (opt name arg . rest)
  64. (leave (G_ "~A: unrecognized option~%") name))
  65. handle-argument
  66. '()))
  67. (unless (assoc-ref opts 'query)
  68. (leave (G_ "missing arguments: no regular expressions to search for~%")))
  69. (guix-package* opts))