all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox] fix prefix for nested commands
Date: Thu,  5 Nov 2020 11:03:01 +0100	[thread overview]
Message-ID: <20201105100301.4212-1-f.ebner@proxmox.com> (raw)

Fixes a regression from commit f50a627f340ca2ae018079e431edd5a127638458
which resulted in re-using the prefix without sub-commands when calling
handle_simple_command(_future)

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

For example,
    proxmox-backup-manager user create foo
is affected by this and printed:
    Usage: proxmox-backup-manager <userid> [OPTIONS]
instead of:
    Usage: proxmox-backup-manager user create <userid> [OPTIONS]

 proxmox/src/api/cli/command.rs | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/proxmox/src/api/cli/command.rs b/proxmox/src/api/cli/command.rs
index 53e3d93..89dfdf1 100644
--- a/proxmox/src/api/cli/command.rs
+++ b/proxmox/src/api/cli/command.rs
@@ -148,12 +148,11 @@ fn handle_simple_command(
 }
 
 fn parse_nested_command<'a>(
-    prefix: &str,
+    prefix: &mut String,
     def: &'a CliCommandMap,
     args: &mut Vec<String>,
 ) -> Result<&'a CliCommand, Error> {
     let mut map = def;
-    let mut prefix = prefix.to_string();
 
     // Note: Avoid async recursive function, because current rust compiler cant handle that
     loop {
@@ -185,7 +184,7 @@ fn parse_nested_command<'a>(
             }
         };
 
-        prefix = format!("{} {}", prefix, command);
+        *prefix = format!("{} {}", prefix, command);
 
         match sub_cmd {
             CommandLineInterface::Simple(cli_cmd) => {
@@ -277,7 +276,8 @@ pub async fn handle_command_future(
             handle_simple_command_future(&prefix, &cli_cmd, args, rpcenv).await
         }
         CommandLineInterface::Nested(ref map) => {
-            let cli_cmd = parse_nested_command(&prefix, &map, &mut args)?;
+            let mut prefix = prefix.to_string();
+            let cli_cmd = parse_nested_command(&mut prefix, &map, &mut args)?;
             handle_simple_command_future(&prefix, &cli_cmd, args, rpcenv).await
         }
     };
@@ -305,7 +305,8 @@ pub fn handle_command(
             handle_simple_command(&prefix, &cli_cmd, args, rpcenv, run)
         }
         CommandLineInterface::Nested(ref map) => {
-            let cli_cmd = parse_nested_command(&prefix, &map, &mut args)?;
+            let mut prefix = prefix.to_string();
+            let cli_cmd = parse_nested_command(&mut prefix, &map, &mut args)?;
             handle_simple_command(&prefix, &cli_cmd, args, rpcenv, run)
         }
     };
-- 
2.20.1





             reply	other threads:[~2020-11-05 10:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05 10:03 Fabian Ebner [this message]
2020-11-05 10:23 ` [pbs-devel] applied: " Wolfgang Bumiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201105100301.4212-1-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal