Skip to content

Commit

Permalink
start
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod committed Nov 14, 2023
1 parent 21214db commit a39f81e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cargo-near/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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"
))]
Expand Down
26 changes: 26 additions & 0 deletions cargo-near/src/commands/new/mod.rs
Original file line number Diff line number Diff line change
@@ -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: &<New as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
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)
}
}

0 comments on commit a39f81e

Please sign in to comment.