From 627cf466f09300fc7d863a09118a5e865b5c9fb1 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 14 Mar 2024 16:56:16 +0100 Subject: [PATCH] virsh-checkpoint: Make 'checkpointname' positional and required MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The argument was being parsed positionally due to the command parser quirk as we didn't opt out of it. Since the code in virshLookupCheckpoint requires that the checkpointname is present we can mark all the options as positional and required and remove the redundant check from virshLookupCheckpoint. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- tools/virsh-checkpoint.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index 65061cbf3d..9aeb8a5e7e 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -281,16 +281,8 @@ virshLookupCheckpoint(vshControl *ctl, if (vshCommandOptStringReq(ctl, cmd, arg, &chkname) < 0) return -1; - if (chkname) { - *chk = virDomainCheckpointLookupByName(dom, chkname, 0); - } else { - vshError(ctl, _("--%1$s is required"), arg); + if (!(*chk = virDomainCheckpointLookupByName(dom, chkname, 0))) return -1; - } - if (!*chk) { - vshReportError(ctl); - return -1; - } *name = virDomainCheckpointGetName(*chk); return 0; @@ -309,6 +301,8 @@ static const vshCmdOptDef opts_checkpoint_edit[] = { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT), {.name = "checkpointname", .type = VSH_OT_STRING, + .positional = true, + .required = true, .help = N_("checkpoint name"), .completer = virshCheckpointNameCompleter, }, @@ -420,6 +414,8 @@ static const vshCmdOptDef opts_checkpoint_info[] = { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT), {.name = "checkpointname", .type = VSH_OT_STRING, + .positional = true, + .required = true, .help = N_("checkpoint name"), .completer = virshCheckpointNameCompleter, }, @@ -810,6 +806,8 @@ static const vshCmdOptDef opts_checkpoint_dumpxml[] = { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT), {.name = "checkpointname", .type = VSH_OT_STRING, + .positional = true, + .required = true, .help = N_("checkpoint name"), .completer = virshCheckpointNameCompleter, }, @@ -886,6 +884,8 @@ static const vshCmdOptDef opts_checkpoint_parent[] = { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT), {.name = "checkpointname", .type = VSH_OT_STRING, + .positional = true, + .required = true, .help = N_("find parent of checkpoint name"), .completer = virshCheckpointNameCompleter, }, @@ -935,6 +935,8 @@ static const vshCmdOptDef opts_checkpoint_delete[] = { VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name = "checkpointname", .type = VSH_OT_STRING, + .positional = true, + .required = true, .help = N_("checkpoint name"), .completer = virshCheckpointNameCompleter, },