ui.scm 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; ui.scm --- User interface module for Guile-Daemon
  2. ;; Copyright © 2016 Alex Kost <alezost@gmail.com>
  3. ;; This file is part of Guile-Daemon.
  4. ;; Guile-Daemon is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;;
  9. ;; Guile-Daemon is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with Guile-Daemon. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This module provides subroutines to parse command-line arguments for
  18. ;; guile-daemon.
  19. ;;; Code:
  20. (define-module (daemon ui)
  21. #:use-module (srfi srfi-37)
  22. #:use-module (daemon config)
  23. #:use-module (daemon defaults)
  24. #:use-module (daemon utils)
  25. #:export (show-help
  26. show-version
  27. parse-args))
  28. (define (show-help)
  29. (display "Usage: guile-daemon [OPTIONS...]
  30. Run Guile Daemon.")
  31. (display "\n
  32. Options:
  33. -h, --help display this help and exit
  34. -V, --version display version information and exit
  35. -c, --config=FILE load startup configuration from FILE
  36. -f, --fifo=FILE use fifo FILE
  37. -s, --socket=FILE use socket FILE
  38. "))
  39. (define (show-version)
  40. (print-output "~a ~a" %package-name %version)
  41. (print-output "Copyright (C) ~a Alex Kost
  42. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  43. This is free software: you are free to change and redistribute it.
  44. There is NO WARRANTY, to the extent permitted by law."
  45. %copyright-year))
  46. (define %default-options
  47. `((config-file . ,%default-config-file)
  48. (fifo-file . ,%default-fifo-file)
  49. (socket-file . ,%default-socket-file)))
  50. (define %options
  51. (list (option '(#\h "help") #f #f
  52. (lambda _
  53. (show-help)
  54. (exit 0)))
  55. (option '(#\V "version") #f #f ; 'v' is for 'verbose'
  56. (lambda _
  57. (show-version)
  58. (exit 0)))
  59. (option '(#\c "config") #t #f
  60. (lambda (opt name arg seed)
  61. (alist-replace 'config-file arg seed)))
  62. (option '(#\f "fifo") #t #f
  63. (lambda (opt name arg seed)
  64. (alist-replace 'fifo-file arg seed)))
  65. (option '(#\s "socket") #t #f
  66. (lambda (opt name arg seed)
  67. (alist-replace 'socket-file arg seed)))))
  68. (define (parse-args args)
  69. "Return alist of options from command-line ARGS."
  70. (args-fold args %options
  71. (lambda (opt name arg seed)
  72. (print-error "Unrecognized option: ~a" name)
  73. seed)
  74. (lambda (arg seed)
  75. (print-error "Unneeded argument: ~a" arg)
  76. seed)
  77. %default-options))
  78. ;;; ui.scm ends here