Pino Toscano
2016-Jan-14 11:43 UTC
[Libguestfs] [PATCH 1/2] builder: move os-version search in own function
Simple code motion, no behaviour changes. --- builder/builder.ml | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/builder/builder.ml b/builder/builder.ml index 9c26573..ec9919f 100644 --- a/builder/builder.ml +++ b/builder/builder.ml @@ -75,6 +75,30 @@ let remove_duplicates index false ) index +(* Look for the specified os-version, resolving it as alias first. *) +let selected_cli_item cmdline index + let arg + (* Try to resolve the alias. *) + try + let item + List.find ( + fun (name, { Index.aliases = aliases }) -> + match aliases with + | None -> false + | Some l -> List.mem cmdline.arg l + ) index in + fst item + with Not_found -> cmdline.arg in + let item + try List.find ( + fun (name, { Index.arch = a }) -> + name = arg && cmdline.arch = normalize_arch a + ) index + with Not_found -> + error (f_"cannot find os-version '%s' with architecture '%s'.\nUse --list to list available guest types.") + arg cmdline.arch in + item + let main () (* Command line argument parsing - see cmdline.ml. *) let cmdline = parse_cmdline () in @@ -229,26 +253,8 @@ let main () | (`Install|`Notes) as mode -> mode in (* Which os-version (ie. index entry)? *) - let arg - (* Try to resolve the alias. *) - try - let item - List.find ( - fun (name, { Index.aliases = aliases }) -> - match aliases with - | None -> false - | Some l -> List.mem cmdline.arg l - ) index in - fst item - with Not_found -> cmdline.arg in - let item - try List.find ( - fun (name, { Index.arch = a }) -> - name = arg && cmdline.arch = normalize_arch a - ) index - with Not_found -> - error (f_"cannot find os-version '%s' with architecture '%s'.\nUse --list to list available guest types.") - arg cmdline.arch in + let item = selected_cli_item cmdline index in + let arg = fst item in let entry = snd item in let sigchecker = entry.Index.sigchecker in -- 2.5.0
Pino Toscano
2016-Jan-14 11:43 UTC
[Libguestfs] [PATCH 2/2] builder: allow a specific template for --list
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
Richard W.M. Jones
2016-Jan-14 12:53 UTC
Re: [Libguestfs] [PATCH 2/2] builder: allow a specific template for --list
ACK series. - - - BTW, as RHEL 7.3 has now rebased on to 1.32, any features which are required to be backported to RHEL 7.3 must have a separate BZ filed. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Maybe Matching Threads
- [PATCH 2/2] builder: allow a specific template for --list
- [PATCH] builder: Make the interface between cmdline.ml and builder.ml explicit.
- [PATCH v11 3/8] builder: change arch type to (string, string option) maybe.
- [PATCH v13 1/3] builder: change arch type to distinguish guesses
- [PATCH v12 1/3] builder: change arch type to distinguish guesses