virt-builder: Add --machine-readable option, as in virt-resize and virt-sparsify.

This makes it easier to query the virt-builder binary capabilities,
from external programs.
This commit is contained in:
Richard W.M. Jones
2014-03-29 15:07:54 +00:00
parent 30bdadf032
commit ebda77b647
5 changed files with 51 additions and 0 deletions

View File

@@ -81,6 +81,8 @@ let parse_cmdline () =
eprintf (f_"%s: invalid --list-format type '%s', see the man page.\n") prog fmt;
exit 1 in
let machine_readable = ref false in
let memsize = ref None in
let set_memsize arg = memsize := Some arg in
@@ -134,6 +136,7 @@ let parse_cmdline () =
"--list-format", Arg.String list_set_format,
"short|long|json" ^ " " ^ s_"Set the format for --list (default: short)";
"--long-options", Arg.Unit display_long_options, " " ^ s_"List long options";
"--machine-readable", Arg.Set machine_readable, " " ^ s_"Make output machine readable";
"-m", Arg.Int set_memsize, "mb" ^ " " ^ s_"Set memory size";
"--memsize", Arg.Int set_memsize, "mb" ^ " " ^ s_"Set memory size";
"--network", Arg.Set network, " " ^ s_"Enable appliance network (default)";
@@ -201,6 +204,7 @@ read the man page virt-builder(1).
let format = match !format with "" -> None | s -> Some s in
let gpg = !gpg in
let list_format = !list_format in
let machine_readable = !machine_readable in
let memsize = !memsize in
let network = !network in
let ops = get_customize_ops () in
@@ -211,6 +215,17 @@ read the man page virt-builder(1).
let sources = List.rev !sources in
let sync = !sync in
(* No arguments and machine-readable mode? Print some facts. *)
if args = [] && machine_readable then (
printf "virt-builder\n";
printf "arch\n";
printf "config-file\n";
printf "customize\n";
printf "json-list\n";
if Pxzcat.using_parallel_xzcat () then printf "pxzcat\n";
exit 0
);
(* Check options. *)
let arg =
match mode with

View File

@@ -55,6 +55,12 @@ extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
#define PARALLEL_XZCAT 0
#endif
value
virt_builder_using_parallel_xzcat (value unitv)
{
return PARALLEL_XZCAT ? Val_true : Val_false;
}
#if PARALLEL_XZCAT
static void pxzcat (value filenamev, value outputfilev, unsigned nr_threads);
#endif /* PARALLEL_XZCAT */

View File

@@ -17,3 +17,4 @@
*)
external pxzcat : string -> string -> unit = "virt_builder_pxzcat"
external using_parallel_xzcat : unit -> bool = "virt_builder_using_parallel_xzcat" "noalloc"

View File

@@ -29,3 +29,6 @@ val pxzcat : string -> string -> unit
If liblzma was found at compile time, this uses an internal
implementation of parallel xzcat. Otherwise regular xzcat is
used. *)
val using_parallel_xzcat : unit -> bool
(** Returns [true] iff the implementation uses parallel xzcat. *)

View File

@@ -344,6 +344,12 @@ I<--long> is a shorthand for the C<long> format.
See also: I<--source>, I<--notes>, L</SOURCES OF TEMPLATES>.
=item B<--machine-readable>
This option is used to make the output more machine friendly
when being parsed by other programs. See
L</MACHINE READABLE OUTPUT> below.
=item B<-m> MB
=item B<--memsize> MB
@@ -1542,6 +1548,26 @@ which is normal and harmless.
=back
=head1 MACHINE READABLE OUTPUT
The I<--machine-readable> option can be used to make the output more
machine friendly, which is useful when calling virt-builder from other
programs, GUIs etc.
Use the option on its own to query the capabilities of the
virt-builder binary. Typical output looks like this:
$ virt-builder --machine-readable
virt-builder
arch
config-file
customize
json-list
pxzcat
A list of features is printed, one per line, and the program exits
with status 0.
=head1 ENVIRONMENT VARIABLES
For other environment variables which affect all libguestfs programs,