From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8D6D943CE3; Mon, 18 Mar 2024 12:21:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 92A9440A6E; Mon, 18 Mar 2024 12:21:04 +0100 (CET) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 9F05C40A67 for ; Mon, 18 Mar 2024 12:21:00 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Tysps55x8z1FMs7; Mon, 18 Mar 2024 19:20:37 +0800 (CST) Received: from dggpeml500024.china.huawei.com (unknown [7.185.36.10]) by mail.maildlp.com (Postfix) with ESMTPS id D46A31A0172; Mon, 18 Mar 2024 19:20:58 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 18 Mar 2024 19:20:58 +0800 From: Chengwen Feng To: , CC: Subject: [PATCH v4 1/6] argparse: refine error message Date: Mon, 18 Mar 2024 11:18:33 +0000 Message-ID: <20240318111838.16991-2-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240318111838.16991-1-fengchengwen@huawei.com> References: <20240220131502.47510-1-fengchengwen@huawei.com> <20240318111838.16991-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500024.china.huawei.com (7.185.36.10) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch refines the error message. Signed-off-by: Chengwen Feng --- lib/argparse/rte_argparse.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/argparse/rte_argparse.c b/lib/argparse/rte_argparse.c index 2d953f1694..48738cd07b 100644 --- a/lib/argparse/rte_argparse.c +++ b/lib/argparse/rte_argparse.c @@ -67,7 +67,7 @@ verify_arg_name(const struct rte_argparse_arg *arg) return -EINVAL; } if (arg->name_long[1] != '-') { - ARGPARSE_LOG(ERR, "optional long name %s must only start with '--'", + ARGPARSE_LOG(ERR, "optional long name %s doesn't start with '--'", arg->name_long); return -EINVAL; } @@ -101,7 +101,7 @@ static int verify_arg_help(const struct rte_argparse_arg *arg) { if (arg->help == NULL) { - ARGPARSE_LOG(ERR, "argument %s must have help info!", arg->name_long); + ARGPARSE_LOG(ERR, "argument %s doesn't have help info!", arg->name_long); return -EINVAL; } @@ -116,13 +116,13 @@ verify_arg_has_val(const struct rte_argparse_arg *arg) if (is_arg_positional(arg)) { if (has_val == RTE_ARGPARSE_ARG_REQUIRED_VALUE) return 0; - ARGPARSE_LOG(ERR, "argument %s is positional, should has zero or required-val!", + ARGPARSE_LOG(ERR, "argument %s is positional, must config required-val!", arg->name_long); return -EINVAL; } if (has_val == 0) { - ARGPARSE_LOG(ERR, "argument %s is optional, has-val config wrong!", + ARGPARSE_LOG(ERR, "argument %s is optional, has-value config wrong!", arg->name_long); return -EINVAL; } @@ -140,13 +140,13 @@ verify_arg_saver(const struct rte_argparse *obj, uint32_t index) if (arg->val_saver == NULL) { if (val_type != 0) { - ARGPARSE_LOG(ERR, "argument %s parse by callback, val-type must be zero!", + ARGPARSE_LOG(ERR, "argument %s parsed by callback, value-type should not be set!", arg->name_long); return -EINVAL; } if (obj->callback == NULL) { - ARGPARSE_LOG(ERR, "argument %s parse by callback, but callback is NULL!", + ARGPARSE_LOG(ERR, "argument %s parsed by callback, but callback is NULL!", arg->name_long); return -EINVAL; } @@ -155,12 +155,12 @@ verify_arg_saver(const struct rte_argparse *obj, uint32_t index) } if (val_type == 0 || val_type >= cmp_max) { - ARGPARSE_LOG(ERR, "argument %s val-type config wrong!", arg->name_long); + ARGPARSE_LOG(ERR, "argument %s value-type config wrong!", arg->name_long); return -EINVAL; } if (has_val == RTE_ARGPARSE_ARG_REQUIRED_VALUE && arg->val_set != NULL) { - ARGPARSE_LOG(ERR, "argument %s has required value, val-set should be NULL!", + ARGPARSE_LOG(ERR, "argument %s has required value, value-set should be NULL!", arg->name_long); return -EINVAL; } @@ -175,7 +175,8 @@ verify_arg_flags(const struct rte_argparse *obj, uint32_t index) uint32_t unused_bits = arg_attr_unused_bits(arg); if (unused_bits != 0) { - ARGPARSE_LOG(ERR, "argument %s flags set wrong!", arg->name_long); + ARGPARSE_LOG(ERR, "argument %s flags unused bits should not be set!", + arg->name_long); return -EINVAL; } @@ -189,7 +190,7 @@ verify_arg_flags(const struct rte_argparse *obj, uint32_t index) } if (arg->val_saver != NULL) { - ARGPARSE_LOG(ERR, "argument %s could occur multiple times, should use callback to parse!", + ARGPARSE_LOG(ERR, "argument %s supports multiple times, should use callback to parse!", arg->name_long); return -EINVAL; } @@ -536,8 +537,10 @@ parse_arg_autosave(struct rte_argparse_arg *arg, const char *value) return ret; } +/* arg_parse indicates the name entered by the user, which can be long-name or short-name. */ static int -parse_arg_val(struct rte_argparse *obj, struct rte_argparse_arg *arg, char *value) +parse_arg_val(struct rte_argparse *obj, const char *arg_name, + struct rte_argparse_arg *arg, char *value) { int ret; @@ -546,7 +549,7 @@ parse_arg_val(struct rte_argparse *obj, struct rte_argparse_arg *arg, char *valu else ret = parse_arg_autosave(arg, value); if (ret != 0) { - ARGPARSE_LOG(ERR, "argument %s parse value fail!", arg->name_long); + ARGPARSE_LOG(ERR, "argument %s parse value fail!", arg_name); return ret; } @@ -582,7 +585,7 @@ parse_args(struct rte_argparse *obj, int argc, char **argv, bool *show_help) return -EINVAL; } arg = find_position_arg(obj, position_index); - ret = parse_arg_val(obj, arg, curr_argv); + ret = parse_arg_val(obj, arg->name_long, arg, curr_argv); if (ret != 0) return ret; continue; @@ -629,7 +632,7 @@ parse_args(struct rte_argparse *obj, int argc, char **argv, bool *show_help) /* Do nothing, because it's optional value, only support arg=val or arg. */ } - ret = parse_arg_val(obj, arg, value); + ret = parse_arg_val(obj, arg_name, arg, value); if (ret != 0) return ret; -- 2.17.1