diff options
Diffstat (limited to 'src/mcron/scripts/mcron.scm')
-rw-r--r-- | src/mcron/scripts/mcron.scm | 75 |
1 files changed, 14 insertions, 61 deletions
diff --git a/src/mcron/scripts/mcron.scm b/src/mcron/scripts/mcron.scm index 11c0e34..39733f8 100644 --- a/src/mcron/scripts/mcron.scm +++ b/src/mcron/scripts/mcron.scm @@ -1,6 +1,6 @@ ;;;; mcron -- run jobs at scheduled times -;;; Copyright © 2003, 2012 Dale Mellor <dale_mellor@users.sourceforge.net> -;;; Copyright © 2015, 2016, 2018 Mathieu Lirzin <mthl@gnu.org> +;;; Copyright © 2003, 2012, 2020 Dale Mellor <> +;;; Copyright © 2015, 2016, 2018 Mathieu Lirzin <mthl@gnu.org> ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com> ;;; ;;; This file is part of GNU Mcron. @@ -20,7 +20,6 @@ (define-module (mcron scripts mcron) #:use-module (ice-9 ftw) - #:use-module (ice-9 getopt-long) #:use-module (ice-9 local-eval) #:use-module (ice-9 rdelim) #:use-module (mcron base) @@ -32,31 +31,6 @@ -(define (show-help) - (display "Usage: mcron [OPTION...] [FILE...] -Run an mcron process according to the specifications in the FILE... (`-' for -standard input), or use all the files in ~/.config/cron (or the deprecated -~/.cron) with .guile or .vixie extensions. - - -d, --daemon Run as a daemon process - -i, --stdin=(guile|vixie) Format of data passed as standard input - (default guile) - -s, --schedule[=N] Display the next N (or 8) jobs that will be run - -l, --log Write log messages to standard output - --log-format=FMT (ice-9 format) format string for log messages - --date-format=FMT (srfi srfi-19) date format string for log messages - -?, --help Give this help list - -V, --version Print program version - -Mandatory or optional arguments to long options are also mandatory or optional -for any corresponding short options. - -Report bugs to bug-mcron@gnu.org. - -")) - - - (define process-user-file (let ((guile-regexp (make-regexp "\\.gui(le)?$")) (vixie-regexp (make-regexp "\\.vix(ie)?$"))) @@ -112,44 +86,23 @@ directory. Double-check the folder and file permissions and syntax.")))) ;;; Entry point. ;;; -(define (main) +(define (main --daemon --schedule --stdin --log --log-format --date-format + file-list) - (let ((options - (getopt-long - (command-line) - `((daemon (single-char #\d) (value #f)) - (stdin (single-char #\i) (value #t) - (predicate ,(λ (in) (or (string=? in "guile") - (string=? in "vixie"))))) - (schedule (single-char #\s) (value optional) - (predicate ,string->number)) - (log (single-char #\l) (value #f)) - (log-format (value #t) (predicate ,validate-log-format)) - (date-format (value #t) (predicate ,validate-date-format)) - (help (single-char #\?)) - (version (single-char #\V)))))) - - (cond ((option-ref options 'help #f) (show-help) (exit 0)) - ((option-ref options 'version #f) (show-version "mcron") (exit 0))) - (when config-debug (debug-enable 'backtrace)) - (%process-files (option-ref options '() '()) - (option-ref options 'stdin "guile")) - - (cond ((option-ref options 'schedule #f) + (%process-files file-list (or --stdin "guile")) + (cond (--schedule => (λ (count) - (let ((c (if (string? count) (string->number count) 8))) - (display-schedule (if (exact-integer? c) (max 1 c) 8))) + (display-schedule + (max 1 (inexact->exact (floor (string->number count))))) (exit 0))) - ((option-ref options 'daemon #f) - (case (primitive-fork) - ((0) (setsid)) - (else (exit 0))))) + (--daemon (case (primitive-fork) ((0) (setsid)) + (else (exit 0))))) (parameterize - ((%do-logging (option-ref options 'log (%do-logging))) - (%log-format (option-ref options 'log-format (%log-format))) - (%date-format (option-ref options 'date-format (%date-format)))) - (run-job-loop)))) + ((%do-logging --log) + (%log-format (or --log-format (%log-format))) + (%date-format (or --date-format (%date-format)))) + (catch-mcron-error (run-job-loop)))) |