From 3b95191f7edd41d04b933903497ddc77d56460a5 Mon Sep 17 00:00:00 2001 From: Jianfeng Jiang Date: Wed, 22 May 2024 09:26:25 +0000 Subject: [PATCH] Subcommand `new` should not parse CommonArgs --- docs/src/osdk/reference/commands/new.md | 3 ++ osdk/src/cli.rs | 41 +++++++++++++++---------- osdk/tests/cli/mod.rs | 2 +- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/docs/src/osdk/reference/commands/new.md b/docs/src/osdk/reference/commands/new.md index e914483ea..8e370403f 100644 --- a/docs/src/osdk/reference/commands/new.md +++ b/docs/src/osdk/reference/commands/new.md @@ -22,6 +22,9 @@ Use the kernel template. If this option is not set, the library template will be used by default. +`--library`: +Use the library template. This is the default option. + ## Examples - Create a new kernel named `myos`: diff --git a/osdk/src/cli.rs b/osdk/src/cli.rs index fab56ccd8..b1434f4c3 100644 --- a/osdk/src/cli.rs +++ b/osdk/src/cli.rs @@ -18,32 +18,34 @@ use crate::{ }; pub fn main() { - let (osdk_subcommand, common_args) = match Cli::parse() { - Cli { - cargo_subcommand: CargoSubcommand::Osdk(osdk_subcommand), - common_args, - } => (osdk_subcommand, common_args), - }; - - let load_config = || { + let load_config = |common_args: &CommonArgs| { let manifest = TomlManifest::load(); let scheme = manifest.get_scheme(common_args.scheme.as_ref()); - Config::new(scheme, &common_args) + Config::new(scheme, common_args) }; - match &osdk_subcommand { + let cli = Cli::parse(); + let CargoSubcommand::Osdk(osdk_subcommand) = &cli.cargo_subcommand; + + match osdk_subcommand { OsdkSubcommand::New(args) => execute_new_command(args), OsdkSubcommand::Build(build_args) => { - execute_build_command(&load_config(), build_args); + execute_build_command(&load_config(&build_args.common_args), build_args); } OsdkSubcommand::Run(run_args) => { - execute_run_command(&load_config(), &run_args.gdb_server_args); + execute_run_command( + &load_config(&run_args.common_args), + &run_args.gdb_server_args, + ); } OsdkSubcommand::Debug(debug_args) => { - execute_debug_command(&load_config().run.build.profile, debug_args); + execute_debug_command( + &load_config(&debug_args.common_args).run.build.profile, + debug_args, + ); } OsdkSubcommand::Test(test_args) => { - execute_test_command(&load_config(), test_args); + execute_test_command(&load_config(&test_args.common_args), test_args); } OsdkSubcommand::Check(args) => execute_forwarded_command("check", &args.args), OsdkSubcommand::Clippy(args) => execute_forwarded_command("clippy", &args.args), @@ -57,8 +59,6 @@ pub fn main() { pub struct Cli { #[clap(subcommand)] cargo_subcommand: CargoSubcommand, - #[command(flatten)] - common_args: CommonArgs, } #[derive(Debug, Parser)] @@ -154,12 +154,16 @@ pub struct BuildArgs { value_name = "DIR" )] pub output: Option, + #[command(flatten)] + pub common_args: CommonArgs, } #[derive(Debug, Parser)] pub struct RunArgs { #[command(flatten)] pub gdb_server_args: GdbServerArgs, + #[command(flatten)] + pub common_args: CommonArgs, } #[derive(Debug, Args, Clone, Default)] @@ -197,6 +201,8 @@ pub struct DebugArgs { default_value = ".aster-gdb-socket" )] pub remote: String, + #[command(flatten)] + pub common_args: CommonArgs, } #[derive(Debug, Parser)] @@ -206,6 +212,8 @@ pub struct TestArgs { help = "Only run tests containing this string in their names" )] pub test_name: Option, + #[command(flatten)] + pub common_args: CommonArgs, } #[derive(Debug, Args, Default, Clone, Eq, PartialEq, Serialize, Deserialize)] @@ -255,6 +263,7 @@ impl CargoArgs { } #[derive(Debug, Args)] +/// Common args used for build, run, test and debug subcommand pub struct CommonArgs { #[command(flatten)] pub build_args: CargoArgs, diff --git a/osdk/tests/cli/mod.rs b/osdk/tests/cli/mod.rs index f4338f8f2..ed909baaf 100644 --- a/osdk/tests/cli/mod.rs +++ b/osdk/tests/cli/mod.rs @@ -6,7 +6,7 @@ use crate::util::*; fn cli_help_message() { let output = cargo_osdk(&["-h"]).output().unwrap(); assert_success(&output); - assert_stdout_contains_msg(&output, "cargo osdk [OPTIONS] "); + assert_stdout_contains_msg(&output, "cargo osdk "); } #[test]