* guile: add mu:run-script

This commit is contained in:
djcb
2012-10-22 23:14:39 +03:00
parent 7463e41711
commit b0a60818a0

View File

@ -15,7 +15,7 @@
;; along with this program; if not, write to the Free Software Foundation, ;; along with this program; if not, write to the Free Software Foundation,
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
(define-module (mu script) (define-module (mu script)
:export (mu:run mu:text-only)) :export (mu:run-stats))
(use-modules (ice-9 getopt-long) (ice-9 optargs) (ice-9 popen) (ice-9 format)) (use-modules (ice-9 getopt-long) (ice-9 optargs) (ice-9 popen) (ice-9 format))
(use-modules (mu) (mu stats) (mu plot)) (use-modules (mu) (mu stats) (mu plot))
@ -23,11 +23,12 @@
(define (help-and-exit) (define (help-and-exit)
"Show some help." "Show some help."
(format #t "usage: script [--help] [--textonly] " (format #t "usage: script [--help] [--textonly] "
"[--muhome=<muhome>] [searchexpr]\n") "[--muhome=<muhome>] [--query=<query>\n")
(exit 0)) (exit 0))
(define (mu:run args func) (define (mu:run-stats args func)
"Interpret argument-list ARGS (like command-line "Run some statistics function.
Interpret argument-list ARGS (like command-line
arguments). Possible arguments are: arguments). Possible arguments are:
--help (show some help and exit) --help (show some help and exit)
--muhome (path to alternative mu home directory) --muhome (path to alternative mu home directory)
@ -36,18 +37,18 @@ arguments). Possible arguments are:
then call FUNC with args SEARCHEXPR and TEXTONLY." then call FUNC with args SEARCHEXPR and TEXTONLY."
(setlocale LC_ALL "") (setlocale LC_ALL "")
(let* ((optionspec '( (muhome (value #t)) (let* ((optionspec '( (muhome (value #t))
(what (value #t)) (query (value #t))
(textonly (value #f)) (textonly (value #f))
(help (single-char #\h) (value #f)))) (help (single-char #\h) (value #f))))
(options (getopt-long args optionspec)) (options (getopt-long args optionspec))
(query (option-ref options 'query #f))
(help (option-ref options 'help #f)) (help (option-ref options 'help #f))
(textonly (option-ref options 'textonly #f)) (textonly (option-ref options 'textonly #f))
(muhome (option-ref options 'muhome #f)) (muhome (option-ref options 'muhome #f))
(restargs (option-ref options '() #f)) (restargs (option-ref options '() #f)))
(expr (if restargs (string-join restargs) "")))
(if help (help-and-exit)) (if help (help-and-exit))
(mu:initialize muhome) (mu:initialize muhome)
(func expr textonly))) (func (or query "") textonly)))
;; Local Variables: ;; Local Variables:
;; mode: scheme ;; mode: scheme