disarchive.in 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!@GUILE@ \
  2. --no-auto-compile -e main -L @moddir@ -C @ccachedir@ -s
  3. !#
  4. ;;; Disarchive
  5. ;;; Copyright © 2020-2022 Timothy Sample <samplet@ngyro.com>
  6. ;;;
  7. ;;; This file is part of Disarchive.
  8. ;;;
  9. ;;; Disarchive is free software: you can redistribute it and/or modify
  10. ;;; it under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation, either version 3 of the License, or
  12. ;;; (at your option) any later version.
  13. ;;;
  14. ;;; Disarchive is distributed in the hope that it will be useful,
  15. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with Disarchive. If not, see <http://www.gnu.org/licenses/>.
  21. (use-modules (disarchive config)
  22. (disarchive scripts assemble)
  23. (disarchive scripts disassemble)
  24. (ice-9 getopt-long)
  25. (ice-9 match))
  26. (define options-grammar
  27. '((help (single-char #\h))
  28. (version)))
  29. (define help-message "\
  30. Usage: disarchive [OPTION]... [COMMAND] [COMMAND-OPTION]...
  31. Separate and combine archive file contents and metadata.
  32. Commands:
  33. assemble Recreate an archive from its contents and metadata
  34. disassemble Separate an archive into its contents and metadata
  35. Run 'disarchive COMMAND --help' for help on using COMMAND.
  36. Top-level options:
  37. -h, --help display this help and exit
  38. --version display version information and exit
  39. ")
  40. (define short-help-message "\
  41. Run 'disarchive --help' for usage instructions.
  42. ")
  43. (define (getopt-long* . args)
  44. (catch 'quit
  45. (lambda ()
  46. (apply getopt-long args))
  47. (lambda (_ status)
  48. (display short-help-message (current-error-port))
  49. (exit status))))
  50. (define (main args)
  51. (let ((options (getopt-long* args options-grammar
  52. #:stop-at-first-non-option #t)))
  53. (when (option-ref options 'help #f)
  54. (display help-message)
  55. (exit EXIT_SUCCESS))
  56. (when (option-ref options 'version #f)
  57. (display version-message)
  58. (exit EXIT_SUCCESS))
  59. (match (option-ref options '() '())
  60. (("assemble" args ...) (apply assemble-main "assemble" args))
  61. (("disassemble" args ...) (apply disassemble-main "disassemble" args))
  62. ((cmd . _) (with-output-to-port (current-error-port)
  63. (lambda ()
  64. (format #t "disarchive: No such command: ~a~%" cmd)
  65. (display short-help-message)
  66. (exit EXIT_FAILURE))))
  67. (() (with-output-to-port (current-error-port)
  68. (lambda ()
  69. (display "disarchive: An option or command is required\n")
  70. (display short-help-message)
  71. (exit EXIT_FAILURE)))))))
  72. ;;; Local Variables:
  73. ;;; mode: scheme
  74. ;;; End: