* mu-msg-stats: support cmdline arguments, --muhome etc.
This commit is contained in:
@ -2,29 +2,57 @@
|
|||||||
exec guile -e main -s $0 $@
|
exec guile -e main -s $0 $@
|
||||||
!#
|
!#
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
|
;;
|
||||||
|
;; This program is free software; you can redistribute it and/or modify it
|
||||||
|
;; under the terms of the GNU General Public License as published by the
|
||||||
|
;; Free Software Foundation; either version 3, or (at your option) any
|
||||||
|
;; later version.
|
||||||
|
;;
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
;;
|
||||||
|
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with this program; if not, write to the Free Software Foundation,
|
||||||
|
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
|
||||||
|
(use-modules (ice-9 getopt-long))
|
||||||
(use-modules (mu) (mu stats))
|
(use-modules (mu) (mu stats))
|
||||||
|
|
||||||
(define (main args)
|
(define (main args)
|
||||||
|
(let* ((optionspec '( (muhome (value #t))
|
||||||
(define (usage-exit)
|
(period (value #t))
|
||||||
(display "usage: mu-msg-stats hour|day|month|year [searchexpr]")
|
(help (single-char #\h) (value #f))))
|
||||||
(newline)
|
(options (getopt-long args optionspec))
|
||||||
(exit 1))
|
(msg (string-append
|
||||||
|
"usage: mu-msg-stats [--help] [--muhome=<muhome>] "
|
||||||
(if (not (>= (length args) 2))
|
"--period=<hour|day|month|year> [searchexpr]\n"))
|
||||||
(usage-exit))
|
(help (option-ref options 'help #f))
|
||||||
|
(period (option-ref options 'period #f))
|
||||||
(mu:init)
|
(muhome (option-ref options 'muhome #f))
|
||||||
|
(restargs (option-ref options '() #f))
|
||||||
(let* ((lst (cdr (cdr args)))
|
(expr (if restargs (string-join restargs) "")))
|
||||||
(expr (if lst (string-join lst) "")))
|
(if (or help (not period))
|
||||||
(display expr)
|
(begin
|
||||||
(newline)
|
(display msg)
|
||||||
|
(exit (if help 0 1)))
|
||||||
|
(if (option-ref options 'muhome #f)
|
||||||
|
(mu:init (option-ref options 'muhome))
|
||||||
|
(mu:init)))
|
||||||
(cond
|
(cond
|
||||||
((string= (cadr args) "hour") (mu:plot:per-hour expr))
|
((string= period "hour") (mu:plot:per-hour expr))
|
||||||
((string= (cadr args) "day") (mu:plot:per-weekday expr))
|
((string= period "day") (mu:plot:per-weekday expr))
|
||||||
((string= (cadr args) "month") (mu:plot:per-month expr))
|
((string= period "month") (mu:plot:per-month expr))
|
||||||
((string= (cadr args) "year") (mu:plot:per-year expr))
|
((string= period "year") (mu:plot:per-year expr))
|
||||||
(else (usage-exit)))))
|
(else (begin
|
||||||
|
(display msg)
|
||||||
|
(exit 1))))))
|
||||||
|
|
||||||
|
;; Local Variables:
|
||||||
|
;; mode: scheme
|
||||||
|
;; End:
|
||||||
|
|||||||
Reference in New Issue
Block a user