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 5B43B439D3; Fri, 26 Jan 2024 17:38:41 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2434A40289; Fri, 26 Jan 2024 17:38:41 +0100 (CET) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id AC1CC4021D for ; Fri, 26 Jan 2024 17:38:39 +0100 (CET) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1d7232dcb3eso3917605ad.2 for ; Fri, 26 Jan 2024 08:38:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1706287118; x=1706891918; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=6GIB+wKjoYluLcOZ6ltCyqaxdZecc96LD6oUhZnq50I=; b=EBZQ+sYq1YzQ1qMw1kwT782J3ntVHQa/34dNU0sjEROhTFOYa9UNGYfUzsw9MWzb6t 2O9bLSHT9MaoFU/lianoR/WLcGtZRBcMObiMUk/0IxxeJGARg3Cj/AIRItzVpUiErD2m wOxysTwhhcLTz3LwYwMy+lJyAKWNzvBfhJuiYg+TFcAbpXYqcM6ELYXx+Z9wFhUk6bzI h0yCmDEBsjcS4vfeh8XTOaU+XlISD/3x8CJkiHhRyDlgEl80xjHZXw1/utKPo79H2czY IPPNdxQhnXpVKA5wnYZOn1sRKksk5vFa/oRMFjv/hpdMJ58z/Atrpe8udrYGgd93yYJq kF+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706287118; x=1706891918; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6GIB+wKjoYluLcOZ6ltCyqaxdZecc96LD6oUhZnq50I=; b=unfYrH7r+B1NWM5RhlF2Dr0DsnyvxZEU3hJG6W+XYpDM3n6RCWKMYKkZJKgNjiV9PP Z6VQgzgJwX12SflwMv/XMDYoSBcSWZC+kpRkTsJZFBKdQr1Wleq27NHQdjLRTDtSMF1v h3JeUsbsNO6sltH2VeINUDHDCkTEs+vslE3+F8ES/PKOanEQ7VYMjw3COuqK0zAsJjo3 C2TXxVmwGVZBm3jKQj+2HnxKU7FoKdjar0uelScQ0tp82fTeEY0RCXzpOlFkOT0HJVKG RB5xHY6rEXWiHKYDiODPfQfihqwsruTctrDAIKWTJwKG49n50XZFzfc833Uc62mCLcHq MaaQ== X-Gm-Message-State: AOJu0YxAjKtrQkY60jTHsWaAMdhvYsQ6qDYwd0QBWBqjpv9qFlzs6dvb 77hnmlFoqhE4VUMd1AUHr6Z4jNjvnXwQcSLybBLuwtyeVnnwjVV7g0wNX4u6iXo= X-Google-Smtp-Source: AGHT+IHLF74nIrtZFyZwAdDAU4WR47qx4GqBoQDOaPfZh9VVO7r6boNw+epimkd0OgxVmD/xxBkpZA== X-Received: by 2002:a17:903:a84:b0:1d7:92c3:bbee with SMTP id mo4-20020a1709030a8400b001d792c3bbeemr14922plb.38.1706287118605; Fri, 26 Jan 2024 08:38:38 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id u11-20020a170903308b00b001d70ebd36f7sm1150950plc.106.2024.01.26.08.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 08:38:38 -0800 (PST) Date: Fri, 26 Jan 2024 08:38:36 -0800 From: Stephen Hemminger To: fengchengwen Cc: , , Subject: Re: [24.03 RFC] argparse: add argparse library Message-ID: <20240126083836.319fd282@hermes.local> In-Reply-To: <706f7098-12b3-7365-9d50-d86ee56d4d7a@huawei.com> References: <20231121122651.7078-1-fengchengwen@huawei.com> <20240124075457.0a52c8b1@hermes.local> <706f7098-12b3-7365-9d50-d86ee56d4d7a@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Thu, 25 Jan 2024 14:31:03 +0800 fengchengwen wrote: > Hi Stephen, > > On 2024/1/24 23:54, Stephen Hemminger wrote: > > On Tue, 21 Nov 2023 12:26:51 +0000 > > Chengwen Feng wrote: > > > >> Introduce argparse library (which was inspired by the thread [1]), > >> compared with getopt, the argparse has following advantages: > >> 1) Set the help information when defining parameters. > >> 2) Support positional parameters. > >> > >> The parameters parsing according following: > >> 1) positional: use callback to parse (passed the long-name as the key > >> for callback). > >> 2) optional: > >> In addition to callback to parse, but also support: > >> 2.1) no-val: support set default value to saver. > >> 2.2) has-val: support set value to saver, the value must be conform > >> RTE_ARGPARSE_ARG_VAL_xxx. > >> 2.3) opt-val: if current without value then treat as no-val, else could > >> treat as has-val. > > > > How compatiable is this with Python or other implementations of argparse > > in C? > > This library is a subset of Python argparse, and it don't support some advanced > features, such as: subcommand, exclusive group. We could extend it to support > if needed. > > As for other implementation of argparse in C, I found a interesting site [1], > this library supports all features except the compact/order/wchar. > > [1] https://attractivechaos.wordpress.com/2018/08/31/a-survey-of-argument-parsing-libraries-in-c-c/ I was looking at https://github.com/cofyc/argparse?tab=readme-ov-file One good thing there is that argparse options can be defined in array. Like: struct argparse_option options[] = { OPT_HELP(), OPT_GROUP("Basic options"), OPT_BOOLEAN('f', "force", &force, "force to do", NULL, 0, 0), OPT_BOOLEAN('t', "test", &test, "test only", NULL, 0, 0), OPT_STRING('p', "path", &path, "path to read", NULL, 0, 0), OPT_INTEGER('i', "int", &int_num, "selected integer", NULL, 0, 0), OPT_FLOAT('s', "float", &flt_num, "selected float", NULL, 0, 0), OPT_GROUP("Bits options"), OPT_BIT(0, "read", &perms, "read perm", NULL, PERM_READ, OPT_NONEG), OPT_BIT(0, "write", &perms, "write perm", NULL, PERM_WRITE, 0), OPT_BIT(0, "exec", &perms, "exec perm", NULL, PERM_EXEC, 0), OPT_END(), };