[Pkg-libvirt-commits] [libguestfs] 08/59: Common function to implement --version flag in all OCaml tools (RHBZ#1213247).
Hilko Bengen
bengen at moszumanska.debian.org
Sun May 3 21:26:26 UTC 2015
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit 478a552ab431762dd2a724ade0c3fd84a21b7cab
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Mon Apr 20 08:48:08 2015 +0100
Common function to implement --version flag in all OCaml tools (RHBZ#1213247).
Add a common function print_version_and_exit ~prog () and use this
function to display the version in all OCaml tools, to ensure
consistent output.
---
builder/cmdline.ml | 11 ++++-------
builder/index-validate.c | 4 +++-
customize/customize_main.ml | 11 +++++------
mllib/common_utils.ml | 11 +++++++++++
mllib/common_utils.mli | 4 ++++
resize/resize.ml | 9 +++------
sparsify/cmdline.ml | 10 +++-------
sysprep/main.ml | 11 +++++------
v2v/cmdline.ml | 10 +++-------
9 files changed, 41 insertions(+), 40 deletions(-)
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index 7adde02..7b119d5 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -31,11 +31,6 @@ open Unix
open Printf
let parse_cmdline () =
- let display_version () =
- printf "virt-builder %s\n" Config.package_version;
- exit 0
- in
-
let mode = ref `Install in
let list_mode () = mode := `List in
let notes_mode () = mode := `Notes in
@@ -154,8 +149,10 @@ let parse_cmdline () =
"--no-sync", Arg.Clear sync, " " ^ s_"Do not fsync output file on exit";
"-v", Arg.Set verbose, " " ^ s_"Enable debugging messages";
"--verbose", Arg.Set verbose, " " ^ s_"Enable debugging messages";
- "-V", Arg.Unit display_version, " " ^ s_"Display version and exit";
- "--version", Arg.Unit display_version, " " ^ s_"Display version and exit";
+ "-V", Arg.Unit (print_version_and_exit ~prog),
+ " " ^ s_"Display version and exit";
+ "--version", Arg.Unit (print_version_and_exit ~prog),
+ " " ^ s_"Display version and exit";
"-x", Arg.Set trace, " " ^ s_"Enable tracing of libguestfs calls";
] in
let customize_argspec, get_customize_ops = Customize_cmdline.argspec () in
diff --git a/builder/index-validate.c b/builder/index-validate.c
index 5bb5a2a..9bc2e73 100644
--- a/builder/index-validate.c
+++ b/builder/index-validate.c
@@ -89,7 +89,9 @@ main (int argc, char *argv[])
break;
case 'V':
- printf ("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
+ printf ("%s %s%s\n",
+ guestfs_int_program_name,
+ PACKAGE_VERSION, PACKAGE_VERSION_EXTRA);
exit (EXIT_SUCCESS);
case HELP_OPTION:
diff --git a/customize/customize_main.ml b/customize/customize_main.ml
index 5bba71a..6669c30 100644
--- a/customize/customize_main.ml
+++ b/customize/customize_main.ml
@@ -59,10 +59,7 @@ let main () =
let trace = ref false in
let verbose = ref false in
- let display_version () =
- printf "virt-customize %s\n" Config.package_version;
- exit 0
- and add_file arg =
+ let add_file arg =
let uri =
try URI.parse_uri arg
with Invalid_argument "URI.parse_uri" ->
@@ -103,8 +100,10 @@ let main () =
"--smp", Arg.Int set_smp, "vcpus" ^ " " ^ s_"Set number of vCPUs";
"-v", Arg.Set verbose, " " ^ s_"Enable debugging messages";
"--verbose", Arg.Set verbose, " " ^ s_"Enable debugging messages";
- "-V", Arg.Unit display_version, " " ^ s_"Display version and exit";
- "--version", Arg.Unit display_version, " " ^ s_"Display version and exit";
+ "-V", Arg.Unit (print_version_and_exit ~prog),
+ " " ^ s_"Display version and exit";
+ "--version", Arg.Unit (print_version_and_exit ~prog),
+ " " ^ s_"Display version and exit";
"-x", Arg.Set trace, " " ^ s_"Enable tracing of libguestfs calls";
] in
let customize_argspec, get_customize_ops =
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 0219b7e..0d6a4a6 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -340,6 +340,17 @@ let run_main_and_handle_errors ~prog main =
| exn -> (* something not matched above *)
error ~prog (f_"exception: %s") (Printexc.to_string exn)
+(* Print the version number and exit. Used to implement --version in
+ * the OCaml tools.
+ *)
+let print_version_and_exit ~prog () =
+ let g = G.create () in
+ let { G.major = major; minor = minor;
+ release = release; extra = extra } = G.version g in
+ G.close g;
+ printf "%s %Ld.%Ld.%Ld%s\n%!" prog major minor release extra;
+ exit 0
+
let read_whole_file path =
let buf = Buffer.create 16384 in
let chan = open_in path in
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index 15bd54e..f7d83be 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -78,6 +78,10 @@ val info : prog:string -> ('a, unit, string, unit) format4 -> 'a
val run_main_and_handle_errors : prog:string -> (unit -> unit) -> unit
(** Common function for handling pretty-printing exceptions. *)
+val print_version_and_exit : prog:string -> unit -> unit
+(** Print the version number and exit. Implements [--version] flag in
+ the OCaml tools. *)
+
val read_whole_file : string -> string
(** Read in the whole file as a string. *)
diff --git a/resize/resize.ml b/resize/resize.ml
index 284d0e3..8e69d44 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -155,10 +155,6 @@ let main () =
dryrun, expand, expand_content, extra_partition, format, ignores,
lv_expands, machine_readable, ntfsresize_force, output_format,
quiet, resizes, resizes_force, shrink, sparse, trace, verbose =
- let display_version () =
- printf "virt-resize %s\n" Config.package_version;
- exit 0
- in
let add xs s = xs := s :: !xs in
@@ -229,8 +225,9 @@ let main () =
"--no-sparse", Arg.Clear sparse, " " ^ s_"Turn off sparse copying";
"-v", Arg.Set verbose, " " ^ s_"Enable debugging messages";
"--verbose", Arg.Set verbose, ditto;
- "-V", Arg.Unit display_version, " " ^ s_"Display version and exit";
- "--version", Arg.Unit display_version, ditto;
+ "-V", Arg.Unit (print_version_and_exit ~prog),
+ " " ^ s_"Display version and exit";
+ "--version", Arg.Unit (print_version_and_exit ~prog), ditto;
"-x", Arg.Set trace, " " ^ s_"Enable tracing of libguestfs calls";
] in
long_options := argspec;
diff --git a/sparsify/cmdline.ml b/sparsify/cmdline.ml
index aa42e4a..e8d3e81 100644
--- a/sparsify/cmdline.ml
+++ b/sparsify/cmdline.ml
@@ -32,11 +32,6 @@ type mode_t =
and check_t = [`Ignore|`Continue|`Warn|`Fail]
let parse_cmdline () =
- let display_version () =
- printf "virt-sparsify %s\n" Config.package_version;
- exit 0
- in
-
let add xs s = xs := s :: !xs in
let check_tmpdir = ref `Warn in
@@ -82,8 +77,9 @@ let parse_cmdline () =
"--tmp", Arg.Set_string tmp, s_"block|dir|prebuilt:file" ^ " " ^ s_"Set temporary block device, directory or prebuilt file";
"-v", Arg.Set verbose, " " ^ s_"Enable debugging messages";
"--verbose", Arg.Set verbose, ditto;
- "-V", Arg.Unit display_version, " " ^ s_"Display version and exit";
- "--version", Arg.Unit display_version, ditto;
+ "-V", Arg.Unit (print_version_and_exit ~prog),
+ " " ^ s_"Display version and exit";
+ "--version", Arg.Unit (print_version_and_exit ~prog), ditto;
"-x", Arg.Set trace, " " ^ s_"Enable tracing of libguestfs calls";
"--zero", Arg.String (add zeroes), s_"fs" ^ " " ^ s_"Zero filesystem";
] in
diff --git a/sysprep/main.ml b/sysprep/main.ml
index 8df8db5..4763507 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -53,10 +53,7 @@ let main () =
format_consumed := false
in
- let display_version () =
- printf "virt-sysprep %s\n" Config.package_version;
- exit 0
- and add_file arg =
+ let add_file arg =
let uri =
try URI.parse_uri arg
with Invalid_argument "URI.parse_uri" ->
@@ -149,8 +146,10 @@ let main () =
"--quiet", Arg.Set quiet, " " ^ s_"Don't print log messages";
"-v", Arg.Set verbose, " " ^ s_"Enable debugging messages";
"--verbose", Arg.Set verbose, " " ^ s_"Enable debugging messages";
- "-V", Arg.Unit display_version, " " ^ s_"Display version and exit";
- "--version", Arg.Unit display_version, " " ^ s_"Display version and exit";
+ "-V", Arg.Unit (print_version_and_exit ~prog),
+ " " ^ s_"Display version and exit";
+ "--version", Arg.Unit (print_version_and_exit ~prog),
+ " " ^ s_"Display version and exit";
"-x", Arg.Set trace, " " ^ s_"Enable tracing of libguestfs calls";
] in
let args = basic_args @ Sysprep_operation.extra_args () in
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index eaf8fdc..58ecd62 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -27,11 +27,6 @@ open Types
open Utils
let parse_cmdline () =
- let display_version () =
- printf "virt-v2v %s\n" Config.package_version;
- exit 0
- in
-
let debug_gc = ref false in
let debug_overlays = ref false in
let do_copy = ref true in
@@ -184,8 +179,9 @@ let parse_cmdline () =
Arg.Set_string vdsm_ovf_output, " " ^ s_"Output OVF file";
"-v", Arg.Set verbose, " " ^ s_"Enable debugging messages";
"--verbose", Arg.Set verbose, ditto;
- "-V", Arg.Unit display_version, " " ^ s_"Display version and exit";
- "--version", Arg.Unit display_version, ditto;
+ "-V", Arg.Unit (print_version_and_exit ~prog),
+ " " ^ s_"Display version and exit";
+ "--version", Arg.Unit (print_version_and_exit ~prog), ditto;
"--vmtype", Arg.Set_string vmtype, "server|desktop " ^ s_"Set vmtype (for RHEV)";
"-x", Arg.Set trace, " " ^ s_"Enable tracing of libguestfs calls";
] in
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list