[Libguestfs] [PATCH 2/2] builder: allow a specific template for --list

Pino Toscano ptoscano at redhat.com
Thu Jan 14 11:43:33 UTC 2016


Allow the user to specify a template in --list mode, which will be the
only result in the resulting output (instead of all the available
templates).

This makes it easier to find out the details of a specific template.
---
 builder/builder.ml       |  6 ++++++
 builder/cmdline.ml       |  3 ++-
 builder/virt-builder.pod | 13 +++++++------
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/builder/builder.ml b/builder/builder.ml
index ec9919f..1f9a472 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -213,6 +213,12 @@ let main () =
   let mode =
     match mode with
     | `List ->                          (* --list *)
+      let sources, index =
+        match cmdline.arg with
+        | "" -> sources, index   (* no template -> all the available ones *)
+        | arg ->                 (* just the specified template *)
+          let item = selected_cli_item cmdline index in
+          [], [item] in
       List_entries.list_entries ~list_format:cmdline.list_format ~sources index;
       exit 0
 
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index a077289..f872bd4 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -239,9 +239,10 @@ read the man page virt-builder(1).
       if format <> None then
         error (f_"--list: use '--list-format', not '--format'");
       (match args with
+      | [arg] -> arg
       | [] -> ""
       | _ ->
-        error (f_"--list option does not need any extra arguments")
+        error (f_"too many parameters, at most one 'os-version' is allowed for --list")
       )
     | `Notes ->
       (match args with
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
index 545b134..9a49138 100644
--- a/builder/virt-builder.pod
+++ b/builder/virt-builder.pod
@@ -16,7 +16,7 @@ virt-builder - Build virtual machine images quickly
     [--arch ARCHITECTURE] [--attach ISOFILE]
 __CUSTOMIZE_SYNOPSIS__
 
- virt-builder -l|--list [--long] [--list-format short|long|json]
+ virt-builder -l|--list [--long] [--list-format short|long|json] [os-version]
 
  virt-builder --notes os-version
 
@@ -311,15 +311,16 @@ alternate home directory:
 
  virt-builder --gpg "gpg --homedir /tmp" [...]
 
-=item B<-l>
+=item B<-l> [os-version]
 
-=item B<--list>
+=item B<--list> [os-version]
 
-=item B<--list --list-format> format
+=item B<--list --list-format> format [os-version]
 
-=item B<--list --long>
+=item B<--list --long> [os-version]
 
-List available templates.
+List all the available templates if no guest is specified, or only for the
+specified one.
 
 It is possible to choose with I<--list-format> the output format for the list
 templates:
-- 
2.5.0




More information about the Libguestfs mailing list