ivila commented on code in PR #245:
URL: 
https://github.com/apache/teaclave-trustzone-sdk/pull/245#discussion_r2458298878


##########
cargo-optee/src/main.rs:
##########
@@ -0,0 +1,138 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use anyhow::bail;
+use clap::{Parser, Subcommand};
+use std::env;
+use std::path::PathBuf;
+use std::process::abort;
+
+mod ta_builder;
+
+#[derive(Debug, Parser)]
+#[clap(version = env!("CARGO_PKG_VERSION"))]
+#[clap(about = "Build tool for OP-TEE Rust projects")]
+pub(crate) struct Cli {
+    #[clap(subcommand)]
+    cmd: Command,
+}
+
+#[derive(Debug, Subcommand)]
+enum Command {
+    /// Build a Trusted Application (TA)
+    #[clap(name = "build")]
+    Build {

Review Comment:
   Each build type uses its own set of options, with some overlap.
   Making build_type a subcommand would help developers avoid irrelevant 
options.
   
   For demo:
   ```rust
   use clap::{Parser, Subcommand};
   use std::path::PathBuf;
   
   #[derive(Debug, Parser)]
   struct BuildTypeCommonOptions {
       /// Path to the TA directory (default: current directory)
       #[arg(long = "path", default_value = ".")]
       path: PathBuf,
   
       /// Target architecture: aarch64 or arm (default: aarch64)
       #[arg(long = "arch", default_value = "aarch64")]
       arch: String,
   
       /// Path to the UUID file (default: ../uuid.txt)
       #[arg(long = "uuid_path", default_value = "../uuid.txt")]
       uuid_path: PathBuf,
   
       /// Build in debug mode (default is release)
       #[arg(long = "debug")]
       debug: bool,
   }
   
   #[derive(Debug, Subcommand)]
   enum BuildCommand {
       TA {
           /// Enable std feature for the TA
           #[arg(long = "std")]
           std: bool,
   
           /// Path to the TA dev kit directory (mandatory)
           #[arg(long = "ta_dev_kit_dir", required = true)]
           ta_dev_kit_dir: PathBuf,
   
           /// Path to the TA signing key (default: 
$(TA_DEV_KIT_DIR)/keys/default_ta.pem)
           #[arg(long = "signing_key")]
           signing_key: Option<PathBuf>,
   
           #[command(flatten)]
           common: BuildTypeCommonOptions,
       },
   }
   
   #[derive(Debug, Subcommand)]
   enum Command {
       /// Build a Trusted Application (TA)
       #[clap(name = "build")]
       #[command(subcommand)]
       Build(BuildCommand),
   }
   
   #[derive(Debug, Parser)]
   #[clap(version = env!("CARGO_PKG_VERSION"))]
   #[clap(about = "Build tool for OP-TEE Rust projects")]
   pub(crate) struct Cli {
       #[clap(subcommand)]
       cmd: Command,
   }
   
   
   fn main() {
       Cli::parse();
   }
   ```
   
   Developers will run `${cmd} build ta --${options}` instead of `${cmd} build 
--build_ta=ta --${options}`, and they will get clearer help messages(only the 
relevant options involve)
   
   <img width="780" height="419" alt="image" 
src="https://github.com/user-attachments/assets/bbb6f353-e947-4e55-869c-29f8a718237b";
 />
   
   



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