mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
virsh: Simplify vshTableRowAppend() calling in cmdList(), part two
Instead of having many if-else statements, each with its own vshTableRowAppend() call, we can use a simple trick - have an array of string pointers, set array members in the if bodies and then call vshTableRowAppend() once. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
cf0e0715e0
commit
f644cba8ae
@ -1891,6 +1891,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
||||
if (optTable) {
|
||||
const char *domName = virDomainGetName(dom);
|
||||
const char *stateStr = NULL;
|
||||
g_autofree char *title = NULL;
|
||||
const char *arg[2] = {};
|
||||
|
||||
state = virshDomainState(ctl, dom, NULL);
|
||||
|
||||
@ -1906,43 +1908,33 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
|
||||
if (optTitle && !optUUID) {
|
||||
g_autofree char *title = NULL;
|
||||
|
||||
if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
|
||||
goto cleanup;
|
||||
if (vshTableRowAppend(table, id_buf,
|
||||
domName, stateStr,
|
||||
title, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
arg[0] = title;
|
||||
} else if (optUUID && !optTitle) {
|
||||
if (virDomainGetUUIDString(dom, uuid) < 0) {
|
||||
vshError(ctl, "%s", _("Failed to get domain's UUID"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (vshTableRowAppend(table, id_buf,
|
||||
domName, stateStr,
|
||||
uuid, NULL) < 0)
|
||||
goto cleanup;
|
||||
} else if (optUUID && optTitle) {
|
||||
g_autofree char *title = NULL;
|
||||
|
||||
arg[0] = uuid;
|
||||
} else if (optUUID && optTitle) {
|
||||
if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
|
||||
goto cleanup;
|
||||
if (virDomainGetUUIDString(dom, uuid) < 0) {
|
||||
vshError(ctl, "%s", _("Failed to get domain's UUID"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (vshTableRowAppend(table, id_buf,
|
||||
domName, stateStr,
|
||||
title, uuid, NULL) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (vshTableRowAppend(table, id_buf,
|
||||
domName, stateStr,
|
||||
NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
arg[0] = title;
|
||||
arg[1] = uuid;
|
||||
}
|
||||
|
||||
if (vshTableRowAppend(table, id_buf,
|
||||
domName, stateStr,
|
||||
arg[0], arg[1], NULL) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (optUUID) {
|
||||
if (virDomainGetUUIDString(dom, uuid) < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user