From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 762E91FF15E for ; Fri, 9 Aug 2024 10:25:18 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D202C39FCF; Fri, 9 Aug 2024 10:25:29 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 9 Aug 2024 10:25:25 +0200 Message-Id: <20240809082525.864042-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [docs.rs, format.rs] Subject: [pbs-devel] [PATCH proxmox] router: sort cli properties in usage output X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" If we don't do this, then properties from a serde flattened struct will be positioned at the end of the list, rather than properly sorted with the other properties. Since the tests also feature non-sorted properties, we have to adapt them too. Signed-off-by: Dominik Csapak --- i wanted to add tests for the serde flattened structs, but the test don't use the api macro, nor serde, so i was not sure how i could replicate that. If somebody has an idea for that, please tell, then I'll send a v2 or follow up proxmox-router/src/cli/format.rs | 20 ++++++++++++----- proxmox-router/tests/docs.rs | 38 ++++++++++++++++---------------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/proxmox-router/src/cli/format.rs b/proxmox-router/src/cli/format.rs index 6f0ec50c..a35821a6 100644 --- a/proxmox-router/src/cli/format.rs +++ b/proxmox-router/src/cli/format.rs @@ -139,7 +139,10 @@ pub(crate) fn generate_usage_str_do<'cli>( let mut options = String::new(); - for (prop, optional, param_schema) in schema.properties() { + let mut properties: Vec<_> = schema.properties().collect(); + properties.sort_by(|a, b| a.0.cmp(b.0)); + + for (prop, optional, param_schema) in properties { if done_hash.contains(prop) { continue; } @@ -212,9 +215,12 @@ pub(crate) fn generate_usage_str_do<'cli>( let mut global_options = String::new(); - for (name, _optional, param_schema) in - global_options_iter.flat_map(|o| o.schema.any_object().unwrap().properties()) - { + let mut properties: Vec<_> = global_options_iter + .flat_map(|o| o.schema.any_object().unwrap().properties()) + .collect(); + properties.sort_by(|a, b| a.0.cmp(b.0)); + + for (name, _optional, param_schema) in properties { if done_hash.contains(name) { continue; } @@ -325,12 +331,14 @@ impl<'cli> UsageState<'cli> { let mut out = String::new(); let _ = write!(out, "Options available for command group ``{prefix}``:"); for opt in opts { - for (name, _optional, schema) in opt + let mut properties: Vec<_> = opt .schema .any_object() .expect("non-object schema in global optiosn") .properties() - { + .collect(); + properties.sort_by(|a, b| a.0.cmp(b.0)); + for (name, _optional, schema) in properties { let _ = write!( out, "\n\n{}", diff --git a/proxmox-router/tests/docs.rs b/proxmox-router/tests/docs.rs index f23a872a..74bc99b6 100644 --- a/proxmox-router/tests/docs.rs +++ b/proxmox-router/tests/docs.rs @@ -109,26 +109,26 @@ fn expected_toplevel_help_text() -> &'static str { Usage: clicmd help [{}] [OPTIONS] -clicmd l0c1 --required-arg --another-required-arg [OPTIONS] +clicmd l0c1 --another-required-arg --required-arg [OPTIONS] clicmd l0c2 --another-required-arg [OPTIONS] -clicmd l0sub l1c1 --required-arg --another-required-arg [OPTIONS] -clicmd l0sub l1c2 --required-arg --another-required-arg [OPTIONS] +clicmd l0sub l1c1 --another-required-arg --required-arg [OPTIONS] +clicmd l0sub l1c2 --another-required-arg --required-arg [OPTIONS] "## .trim_start() } fn expected_group_help_text() -> &'static str { r##" -Usage: clicmd l0sub l1c1 --required-arg --another-required-arg [OPTIONS] +Usage: clicmd l0sub l1c1 --another-required-arg --required-arg [OPTIONS] Simple API method with one required and one optional argument. - --required-arg - Required string argument. - --another-required-arg A second required string argument. + --required-arg + Required string argument. + Optional parameters: --optional-arg (default=false) @@ -161,16 +161,16 @@ Optional parameters: ---- -``clicmd l0c1 --required-arg --another-required-arg [OPTIONS]`` +``clicmd l0c1 --another-required-arg --required-arg [OPTIONS]`` Simple API method with one required and one optional argument. -``--required-arg`` ```` - Required string argument. - ``--another-required-arg`` ```` A second required string argument. +``--required-arg`` ```` + Required string argument. + Optional parameters: ``--optional-arg`` `` (default=false)`` @@ -205,16 +205,16 @@ Options available for command group ``clicmd l0sub``: ---- -``clicmd l0sub l1c1 --required-arg --another-required-arg [OPTIONS]`` +``clicmd l0sub l1c1 --another-required-arg --required-arg [OPTIONS]`` Simple API method with one required and one optional argument. -``--required-arg`` ```` - Required string argument. - ``--another-required-arg`` ```` A second required string argument. +``--required-arg`` ```` + Required string argument. + Optional parameters: ``--optional-arg`` `` (default=false)`` @@ -228,16 +228,16 @@ Inherited group parameters: ---- -``clicmd l0sub l1c2 --required-arg --another-required-arg [OPTIONS]`` +``clicmd l0sub l1c2 --another-required-arg --required-arg [OPTIONS]`` Simple API method with one required and one optional argument. -``--required-arg`` ```` - Required string argument. - ``--another-required-arg`` ```` A second required string argument. +``--required-arg`` ```` + Required string argument. + Optional parameters: ``--optional-arg`` `` (default=false)`` -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel