base: Add %program-name parameter object.

pull/3/head
Mathieu Lirzin 2016-07-01 14:39:21 +02:00
parent 0f04df2691
commit a62624301b
5 changed files with 44 additions and 20 deletions

View File

@ -11,4 +11,6 @@
(scheme-mode (scheme-mode
. .
((indent-tabs-mode . nil) ((indent-tabs-mode . nil)
(eval . (put 'test-error 'scheme-indent-function 1))
(eval . (put 'make-parameter 'scheme-indent-function 1))
(eval . (put 'with-database 'scheme-indent-function 1))))) (eval . (put 'with-database 'scheme-indent-function 1)))))

View File

@ -28,8 +28,8 @@ exec ${GUILE:-@GUILE@} --no-auto-compile -e main -s "$0" "$@"
(cuirass ui) (cuirass ui)
(ice-9 getopt-long)) (ice-9 getopt-long))
(define* (show-help prog) (define* (show-help)
(simple-format #t "Usage: ~a [OPTIONS] [CACHEDIR]" prog) (simple-format #t "Usage: ~a [OPTIONS] [CACHEDIR]" (%program-name))
(display " (display "
Run Guix job from a git repository cloned in CACHEDIR. Run Guix job from a git repository cloned in CACHEDIR.
@ -113,19 +113,20 @@ DIR if required."
;;; ;;;
(define* (main #:optional (args (command-line))) (define* (main #:optional (args (command-line)))
(let ((opts (getopt-long args %options)) (let ((opts (getopt-long args %options)))
(progname "cuirass")) (parameterize
(cond ((%program-name (car args))
((option-ref opts 'help #f) (%package-database (option-ref opts 'database (%package-database))))
(show-help progname) (cond
(exit 0)) ((option-ref opts 'help #f)
((option-ref opts 'version #f) (show-help)
(show-version progname) (exit 0))
(exit 0)) ((option-ref opts 'version #f)
(else (show-version)
(parameterize ((%package-database (exit 0))
(option-ref opts 'database (%package-database)))) (else
(let* ((specfile (option-ref opts 'file "tests/hello-subset.scm")) (let* ((specfile (option-ref opts 'file "tests/hello-subset.scm"))
(interval (option-ref opts 'interval "60"))
(specs (primitive-load specfile)) (specs (primitive-load specfile))
(args (option-ref opts '() #f)) (args (option-ref opts '() #f))
(cachedir (if (null? args) (cachedir (if (null? args)
@ -148,4 +149,4 @@ DIR if required."
(lambda () (lambda ()
((guix-variable 'store 'close-connection) store))))) ((guix-variable 'store 'close-connection) store)))))
specs) specs)
(sleep (string->number (option-ref opts 'interval "60"))))))))))) (sleep (string->number interval))))))))))

View File

@ -1,6 +1,7 @@
;;;; base.scm - Cuirass base module ;;;; base.scm - Cuirass base module
;;; ;;;
;;; Copyright © 2012, 2016 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2012, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
;;; ;;;
;;; This file is part of Cuirass. ;;; This file is part of Cuirass.
;;; ;;;
@ -20,9 +21,23 @@
(define-module (cuirass base) (define-module (cuirass base)
#:use-module (ice-9 format) #:use-module (ice-9 format)
#:use-module (srfi srfi-19) #:use-module (srfi srfi-19)
#:export (guix-variable #:export (;; Procedures.
with-directory-excursion guix-variable
call-with-time-display)) call-with-time-display
;; Parameters.
%program-name
;; Macros.
with-directory-excursion))
(define %program-name
;; Similar in spirit to Gnulib 'progname' module.
(make-parameter ""
(λ (val)
(cond ((not (string? val))
(scm-error 'wrong-type-arg
"%program-name" "Not a string: ~S" (list #f) #f))
((string-rindex val #\/) => (λ (idx) (substring val (1+ idx))))
(else val)))))
(define (guix-variable module name) (define (guix-variable module name)
"Dynamically link variable NAME under Guix module MODULE and return it. "Dynamically link variable NAME under Guix module MODULE and return it.

View File

@ -18,13 +18,15 @@
;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>. ;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>.
(define-module (cuirass ui) (define-module (cuirass ui)
#:use-module (cuirass base)
#:use-module (cuirass config) #:use-module (cuirass config)
#:export (show-version #:export (show-version
show-package-information)) show-package-information))
(define (show-version prog) (define (show-version)
"Display version information for COMMAND." "Display version information for COMMAND."
(simple-format #t "~a (~a) ~a~%" prog %package-name %package-version) (simple-format #t "~a (~a) ~a~%"
(%program-name) %package-name %package-version)
(display "Copyright (C) 2016 the Cuirass authors (display "Copyright (C) 2016 the Cuirass authors
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. This is free software: you are free to change and redistribute it.

View File

@ -19,3 +19,7 @@
(use-modules (cuirass base) (use-modules (cuirass base)
(srfi srfi-64)) (srfi srfi-64))
(test-error "invalid program name"
'wrong-type-arg
(%program-name #f))