asir66 commented on PR #263:
URL: 
https://github.com/apache/teaclave-trustzone-sdk/pull/263#issuecomment-3727502398

   
   
   
   > For **5.1, "cargo-optee" is not recognized as a cargo subcommand**, it is 
because cargo invokes external binaries in an unexpected way.
   > 
   > For example, `cargo optee build` is invoked as `cargo-optee optee build`. 
This extra "optee" argument causes the subcommand parser to fail.
   > 
   > One workaround is to add a parsing rule or configuration option that 
discards the first (duplicate) argument:
   > 
   > ```rust
   > #[derive(Parser)]
   > #[command(version, about, long_about = None)]
   > struct Cli {
   >     // By stripping the duplicate "optee" argument during subcommand 
invocation, 
   >     // this solution maintains compatibility between standalone and 
cargo-integrated execution modes.
   >     #[arg(name = "tool_name", hide = true)]
   >     _tool_name: String,
   >     #[command(subcommand)]
   >     commands: Commands,
   > }
   > ```
   
   That makes sense—thank you for the suggestion.
   
   I also noticed that with the previous implementation, running cargo-optee in 
standalone mode results in the following error:
   ```
   error: the following required arguments were not provided:
     <tool_name>
   ```
   
   For this reason, I believe the following approach is more robust: making 
_tool_name an optional argument.
   ```rust
   #[derive(Debug, Parser)]
   #[command(version, about)]
   pub struct Cli {
       // By stripping the duplicate "optee" argument during subcommand 
invocation,
       // this solution maintains compatibility between standalone and 
cargo-integrated execution modes.
       // When invoked as `cargo optee build`, cargo passes "optee" as the 
first argument.
       // When invoked as `cargo-optee build`, no extra argument is passed.
       #[arg(name = "tool_name", hide = true)]
       _tool_name: Option<String>,
   
       #[command(subcommand)]
       pub cmd: Command,
   }
   ```
   
   This allows the CLI to work correctly in both invocation scenarios without 
requiring additional conditional logic.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to