diff --git a/cargo-near/src/commands/mod.rs b/cargo-near/src/commands/mod.rs index 691ffca3..6594afde 100644 --- a/cargo-near/src/commands/mod.rs +++ b/cargo-near/src/commands/mod.rs @@ -4,6 +4,7 @@ pub mod abi_command; pub mod build_command; pub mod create_dev_account; pub mod deploy; +pub mod new; #[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(context = near_cli_rs::GlobalContext)] @@ -12,6 +13,11 @@ pub mod deploy; #[non_exhaustive] /// What are you up to? (select one of the options with the up-down arrows on your keyboard and press Enter) pub enum NearCommand { + #[strum_discriminants(strum( + message = "new - Initializes a new project to create a contract" + ))] + /// Initializes a new project to create a contract + New(self::new::New), #[strum_discriminants(strum( message = "build - Build a NEAR contract and optionally embed ABI" ))] diff --git a/cargo-near/src/commands/new/mod.rs b/cargo-near/src/commands/new/mod.rs new file mode 100644 index 00000000..c5e748c6 --- /dev/null +++ b/cargo-near/src/commands/new/mod.rs @@ -0,0 +1,26 @@ +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = near_cli_rs::GlobalContext)] +#[interactive_clap(output_context = NewContext)] +pub struct New { + /// Enter a new project name to create a contract: + pub project_dir: near_cli_rs::types::path_buf::PathBuf, +} + +#[derive(Debug, Clone)] +pub struct NewContext; + +impl NewContext { + pub fn from_previous_context( + _previous_context: near_cli_rs::GlobalContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let project_dir = scope.project_dir.clone(); + std::process::Command::new("cargo") + .arg("new") + .arg(&project_dir) + .arg("--lib") + .output() + .expect("failed to execute process"); + Ok(Self) + } +}