diff --git a/guix-build.in b/guix-build.in index 961545b146e90254302cb835beda1e39a2eff91c..c7bcb389750c24967773a20f431cf28a6c7078f2 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 b574c962b4a0b9566c5a1322faa6786eff89bff7..8d4a8bb055c7a88f45eae78ee5acf9283656365e 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 5b10149d9fd9dc065cfb3561027e14b29f471496..3a226bdca8eca6f32af86da400f57214d3b26167 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 <http://www.gnu.org/licenses/>. (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 cb78a21bd856e0147c05dd4d4b042e018d5f61a2..447c3a9a9f98ac7b31581787620044fae76fd98f 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 @@ (define-syntax-rule (leave fmt args ...) (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)