[pbs-devel] [PATCH proxmox] fix prefix for nested commands

Fabian Ebner f.ebner at proxmox.com
Thu Nov 5 11:03:01 CET 2020


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 at 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






More information about the pbs-devel mailing list