gnu.scm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2016 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
  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 import gnu)
  20. #:use-module (guix ui)
  21. #:use-module (guix utils)
  22. #:use-module (guix scripts)
  23. #:use-module (guix import gnu)
  24. #:use-module (guix scripts import)
  25. #:use-module (srfi srfi-1)
  26. #:use-module (srfi srfi-11)
  27. #:use-module (srfi srfi-37)
  28. #:use-module (ice-9 match)
  29. #:export (guix-import-gnu))
  30. ;;;
  31. ;;; Command-line options.
  32. ;;;
  33. (define %default-options
  34. '((key-download . interactive)))
  35. (define (show-help)
  36. (display (G_ "Usage: guix import gnu [OPTION...] PACKAGE
  37. Return a package declaration template for PACKAGE, a GNU package.\n"))
  38. ;; '--key-download' taken from (guix scripts refresh).
  39. (display (G_ "
  40. --key-download=POLICY
  41. handle missing OpenPGP keys according to POLICY:
  42. 'always', 'never', and 'interactive', which is also
  43. used when 'key-download' is not specified"))
  44. (newline)
  45. (display (G_ "
  46. -h, --help display this help and exit"))
  47. (display (G_ "
  48. -V, --version display version information and exit"))
  49. (newline)
  50. (show-bug-report-information))
  51. (define %options
  52. ;; Specification of the command-line options.
  53. (cons* (option '(#\h "help") #f #f
  54. (lambda args
  55. (show-help)
  56. (exit 0)))
  57. (option '(#\V "version") #f #f
  58. (lambda args
  59. (show-version-and-exit "guix import gnu")))
  60. (option '("key-download") #t #f ;from (guix scripts refresh)
  61. (lambda (opt name arg result)
  62. (match arg
  63. ((or "interactive" "always" "never")
  64. (alist-cons 'key-download (string->symbol arg)
  65. result))
  66. (x
  67. (leave (G_ "unsupported policy: ~a~%")
  68. arg)))))
  69. %standard-import-options))
  70. ;;;
  71. ;;; Entry point.
  72. ;;;
  73. (define (guix-import-gnu . args)
  74. (define (parse-options)
  75. ;; Return the alist of option values.
  76. (parse-command-line args %options (list %default-options)
  77. #:build-options? #f))
  78. (let* ((opts (parse-options))
  79. (args (filter-map (match-lambda
  80. (('argument . value)
  81. value)
  82. (_ #f))
  83. (reverse opts))))
  84. (match args
  85. ((name)
  86. (with-error-handling
  87. (gnu->guix-package name
  88. #:key-download (assoc-ref opts 'key-download))))
  89. (x
  90. (leave (G_ "wrong number of arguments~%"))))))
  91. ;;; gnu.scm ends here