From cd0602290a532ca98e22eade44f617da79ce6de5 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 12 Nov 2020 13:34:51 +0100 Subject: [PATCH] tools: vshCmddefOptParse: Remove 'optional' command validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since vshCmddefCheckInternals now has this check we no longer need it in vshCmddefOptParse. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- tools/vsh.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index cf4ddc1c2c..f92759f219 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -399,7 +399,6 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint64_t *opts_need_arg, uint64_t *opts_required) { size_t i; - bool optional = false; *opts_need_arg = 0; *opts_required = 0; @@ -410,30 +409,17 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint64_t *opts_need_arg, for (i = 0; cmd->opts[i].name; i++) { const vshCmdOptDef *opt = &cmd->opts[i]; - if (opt->type == VSH_OT_BOOL) { - optional = true; + if (opt->type == VSH_OT_BOOL) continue; - } - - if (opt->flags & VSH_OFLAG_REQ_OPT) { - if (opt->flags & VSH_OFLAG_REQ) - *opts_required |= 1ULL << i; - else - optional = true; - continue; - } if (opt->type == VSH_OT_ALIAS) continue; /* skip the alias option */ - *opts_need_arg |= 1ULL << i; - if (opt->flags & VSH_OFLAG_REQ) { - if (optional && opt->type != VSH_OT_ARGV) - return -1; /* mandatory options must be listed first */ + if (!(opt->flags & VSH_OFLAG_REQ_OPT)) + *opts_need_arg |= 1ULL << i; + + if (opt->flags & VSH_OFLAG_REQ) *opts_required |= 1ULL << i; - } else { - optional = true; - } } return 0;