assemble.scm 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ;;; Disarchive
  2. ;;; Copyright © 2020-2022 Timothy Sample <samplet@ngyro.com>
  3. ;;;
  4. ;;; This file is part of Disarchive.
  5. ;;;
  6. ;;; Disarchive is free software: you can redistribute it and/or modify
  7. ;;; it under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation, either version 3 of the License, or
  9. ;;; (at your option) any later version.
  10. ;;;
  11. ;;; Disarchive is distributed in the hope that it will be useful,
  12. ;;; but 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 Disarchive. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (disarchive scripts assemble)
  19. #:use-module (disarchive)
  20. #:use-module (disarchive config)
  21. #:use-module (disarchive utils)
  22. #:use-module (ice-9 getopt-long)
  23. #:use-module (ice-9 match)
  24. #:export (assemble-main))
  25. (define options-grammar
  26. '((output (single-char #\o) (value #t))
  27. (help (single-char #\h))
  28. (version)))
  29. (define help-message "\
  30. Usage: disarchive assemble [OPTION]... DIRECTORY SPECIFICATION
  31. Assemble DIRECTORY into an archive following SPECIFICATION.
  32. If SPECIFICATION is set to '-', it will be read from standard input.
  33. Options:
  34. -o, --output=FILE write archive to FILE instead of standard output
  35. -h, --help display this help and exit
  36. --version display version information and exit
  37. ")
  38. (define short-help-message "\
  39. Run 'disarchive assmeble --help' for usage instructions.
  40. ")
  41. (define (getopt-long* . args)
  42. (catch 'quit
  43. (lambda ()
  44. (apply getopt-long args))
  45. (lambda (_ status)
  46. (display short-help-message (current-error-port))
  47. (exit status))))
  48. (define (make-resolver input)
  49. (lambda (addresses output)
  50. (copy-recursively input output #:log (%make-void-port "w"))))
  51. (define (assemble-main . args)
  52. (%disarchive-log-port (current-error-port))
  53. (let ((options (getopt-long* args options-grammar)))
  54. (when (option-ref options 'help #f)
  55. (display help-message)
  56. (exit EXIT_SUCCESS))
  57. (when (option-ref options 'version #f)
  58. (display version-message)
  59. (exit EXIT_SUCCESS))
  60. (match (option-ref options '() '())
  61. ((directory specification)
  62. (let ((input (if (string=? specification "-")
  63. (current-input-port)
  64. specification))
  65. (output (option-ref options 'output (current-output-port))))
  66. (disarchive-assemble input output
  67. #:resolver (make-resolver directory)))
  68. (exit EXIT_SUCCESS))
  69. (_ (with-output-to-port (current-error-port)
  70. (lambda ()
  71. (display "\
  72. disarchive assemble: Both a directory and specification are required.
  73. ")
  74. (display short-help-message)
  75. (exit EXIT_FAILURE)))))))