On 01/06/2017 09:42 AM, Chen Hanxiao wrote: > From: Chen Hanxiao <chenhanxiao@xxxxxxxxx> > > This patch will allow --uuid and --name in one cmd. > The pool's UUID and name will be printed side by side. > > Signed-off-by: Chen Hanxiao <chenhanxiao@xxxxxxxxx> > --- > tools/virsh-pool.c | 8 +++++++- > tools/virsh.pod | 5 ++++- > 2 files changed, 11 insertions(+), 2 deletions(-) > > diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c > index da43199..ebe1f68 100644 > --- a/tools/virsh-pool.c > +++ b/tools/virsh-pool.c > @@ -1320,7 +1320,13 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) > for (i = 0; i < list->npools; i++) { > char uuid_str[VIR_UUID_STRING_BUFLEN]; > virStoragePoolGetUUIDString(list->pools[i], uuid_str); > - vshPrint(ctl, "%-36s\n", uuid_str); > + if (!name) { > + vshPrint(ctl, "%-36s\n", uuid_str); > + } else { > + const char *name_str = > + virStoragePoolGetName(list->pools[i]); > + vshPrint(ctl, "%-36s %-10s\n", uuid_str, name_str); > + } Rather than two separate loops - it should just be one loop and rather than -10s for name, I kept with the -20s. See the hunk below which I squashed in before pushing the series. I've also added a news.xml entry for this Thanks! John > } > ret = true; > goto cleanup; > diff --git a/tools/virsh.pod b/tools/virsh.pod > index 463762a..553115e 100644 > --- a/tools/virsh.pod > +++ b/tools/virsh.pod > @@ -3623,7 +3623,10 @@ In addition, there are several sets of filtering flags. I<--persistent> is to > list the persistent pools, I<--transient> is to list the transient pools. > I<--autostart> lists the autostarting pools, I<--no-autostart> lists the pools > with autostarting disabled. If I<--uuid> is specified only pool's UUIDs are printed. > -If I<--name> is specified only pool's names are printed. > +If I<--name> is specified only pool's names are printed. If both I<--name> > +and I<--uuid> are specified, pool's UUID and names are printed side by side > +without any header. Options I<--uuid> and I<--name> are mutually exclusive > +if option I<--details> is specified. > > You may also want to list pools with specified types using I<type>, the > pool types must be separated by comma, e.g. --type dir,disk. The valid pool > diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 85124e8..7a74ba0 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1316,31 +1316,23 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) /* Output basic info then return if --details option not selected */ if (!details) { - if (uuid) { + if (uuid || name) { for (i = 0; i < list->npools; i++) { - char uuid_str[VIR_UUID_STRING_BUFLEN]; - virStoragePoolGetUUIDString(list->pools[i], uuid_str); - if (!name) { - vshPrint(ctl, "%-36s\n", uuid_str); - } else { + if (uuid) { + char uuid_str[VIR_UUID_STRING_BUFLEN]; + virStoragePoolGetUUIDString(list->pools[i], uuid_str); + vshPrint(ctl, "%-36s%c", uuid_str, name ? ' ': '\n'); + } + if (name) { const char *name_str = virStoragePoolGetName(list->pools[i]); - vshPrint(ctl, "%-36s %-10s\n", uuid_str, name_str); + vshPrint(ctl, "%-20s\n", name_str); } } ret = true; goto cleanup; } - if (name) { - for (i = 0; i < list->npools; i++) { - const char *name_str = virStoragePoolGetName(list->pools[i]); - vshPrint(ctl, "%-20s\n", name_str); - } - ret = true; - goto cleanup; - } - /* Output old style header */ vshPrintExtra(ctl, " %-20s %-10s %-10s\n", _("Name"), _("State"), _("Autostart")); -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list