From cdd5d6f95f416078509bce509b25c7c854da34a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sat, 3 Nov 2012 21:19:43 +0100 Subject: [PATCH] ui: Factorize `--version'. * guix/ui.scm (show-version-and-exit): New procedure. * guix-build.in (show-version): Remove. (%options)["version"]: Use `show-version-and-exit'. * guix-download.in: Likewise. * guix-package.in: Likewise. --- guix-build.in | 6 +----- guix-download.in | 6 +----- guix-package.in | 7 ++----- guix/ui.scm | 8 ++++++++ 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/guix-build.in b/guix-build.in index 961545b146..c7bcb38975 100644 --- a/guix-build.in +++ b/guix-build.in @@ -71,9 +71,6 @@ When SOURCE? is true, return the derivations of the package sources." `((system . ,(%current-system)) (substitutes? . #t))) -(define (show-version) - (display "guix-build (@PACKAGE_NAME@) @PACKAGE_VERSION@\n")) - (define (show-help) (display (_ "Usage: guix-build [OPTION]... PACKAGE-OR-DERIVATION... Build the given PACKAGE-OR-DERIVATION and return their output paths.\n")) @@ -113,8 +110,7 @@ Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@")) (exit 0))) (option '(#\V "version") #f #f (lambda args - (show-version) - (exit 0))) + (show-version-and-exit "guix-build"))) (option '(#\S "source") #f #f (lambda (opt name arg result) diff --git a/guix-download.in b/guix-download.in index b574c962b4..8d4a8bb055 100644 --- a/guix-download.in +++ b/guix-download.in @@ -88,9 +88,6 @@ exec ${GUILE-@GUILE@} -L "@guilemoduledir@" -l "$0" \ ;; Alist of default option values. `((format . ,bytevector->nix-base32-string))) -(define (show-version) - (display "guix-download (@PACKAGE_NAME@) @PACKAGE_VERSION@\n")) - (define (show-help) (display (_ "Usage: guix-download [OPTION]... URL Download the file at URL, add it to the store, and print its store path @@ -131,8 +128,7 @@ Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@")) (exit 0))) (option '(#\V "version") #f #f (lambda args - (show-version) - (exit 0))))) + (show-version-and-exit "guix-download"))))) ;;; diff --git a/guix-package.in b/guix-package.in index 5b10149d9f..3a226bdca8 100644 --- a/guix-package.in +++ b/guix-package.in @@ -30,6 +30,7 @@ exec ${GUILE-@GUILE@} -L "@guilemoduledir@" -l "$0" \ ;;; along with Guix. If not, see . (define-module (guix-package) + #:use-module (guix ui) #:use-module (guix store) #:use-module (guix derivations) #:use-module (guix packages) @@ -192,9 +193,6 @@ all of PACKAGES, a list of name/version/output/path tuples." (format (current-error-port) fmt args ...) (exit 1))) -(define (show-version) - (display "guix-package (@PACKAGE_NAME@) @PACKAGE_VERSION@\n")) - (define (show-help) (display (_ "Usage: guix-package [OPTION]... PACKAGES... Install, remove, or upgrade PACKAGES in a single transaction.\n")) @@ -228,8 +226,7 @@ Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@")) (exit 0))) (option '(#\V "version") #f #f (lambda args - (show-version) - (exit 0))) + (show-version-and-exit "guix-package"))) (option '(#\i "install") #t #f (lambda (opt name arg result) diff --git a/guix/ui.scm b/guix/ui.scm index cb78a21bd8..447c3a9a9f 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -19,12 +19,14 @@ (define-module (guix ui) #:use-module (guix utils) #:use-module (guix store) + #:use-module (guix config) #:use-module (guix packages) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) #:export (_ N_ leave + show-version-and-exit call-with-error-handling with-error-handling)) @@ -46,6 +48,12 @@ (format (current-error-port) fmt args ...) (exit 1))) +(define* (show-version-and-exit #:optional (command (car (command-line)))) + "Display version information for COMMAND and `(exit 0)'." + (simple-format #t "~a (~a) ~a~%" + command %guix-package-name %guix-version) + (exit 0)) + (define (call-with-error-handling thunk) "Call THUNK within a user-friendly error handler." (guard (c ((package-input-error? c)