#include "virsecret.h"
#include "virstring.h"
#include "virtime.h"
+#include "vsh-table.h"
static virSecretPtr
virshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
virshSecretListPtr list = NULL;
bool ret = false;
unsigned int flags = 0;
+ vshTablePtr table = NULL;
if (vshCommandOptBool(cmd, "ephemeral"))
flags |= VIR_CONNECT_LIST_SECRETS_EPHEMERAL;
if (!(list = virshSecretListCollect(ctl, flags)))
return false;
- vshPrintExtra(ctl, " %-36s %s\n", _("UUID"), _("Usage"));
- vshPrintExtra(ctl, "----------------------------------------"
- "----------------------------------------\n");
+ table = vshTableNew(_("UUID"), _("Usage"), NULL);
+ if (!table)
+ goto cleanup;
for (i = 0; i < list->nsecrets; i++) {
virSecretPtr sec = list->secrets[i];
int usageType = virSecretGetUsageType(sec);
const char *usageStr = virSecretUsageTypeToString(usageType);
char uuid[VIR_UUID_STRING_BUFLEN];
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ VIR_AUTOFREE(char *) usage = NULL;
if (virSecretGetUUIDString(sec, uuid) < 0) {
vshError(ctl, "%s", _("Failed to get uuid of secret"));
}
if (usageType) {
- vshPrint(ctl, " %-36s %s %s\n",
- uuid, usageStr,
- virSecretGetUsageID(sec));
+ virBufferStrcat(&buf, usageStr, " ",
+ virSecretGetUsageID(sec), NULL);
+ usage = virBufferContentAndReset(&buf);
+ if (!usage)
+ goto cleanup;
+
+ if (vshTableRowAppend(table, uuid, usage, NULL) < 0)
+ goto cleanup;
} else {
- vshPrint(ctl, " %-36s %s\n",
- uuid, _("Unused"));
+ if (vshTableRowAppend(table, uuid, _("Unused"), NULL) < 0)
+ goto cleanup;
}
}
+ vshTablePrintToStdout(table, ctl);
+
ret = true;
cleanup:
+ vshTableFree(table);
virshSecretListFree(list);
return ret;
}