Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod committed Sep 21, 2023
1 parent ed61413 commit 69d1c88
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use near_abi::BuildInfo;
use sha2::{Digest, Sha256};
use std::io::BufRead;

use crate::abi_command::abi;
use crate::abi_command::abi::{AbiCompression, AbiFormat, AbiResult};
use crate::commands::abi_command::abi;
use crate::commands::abi_command::abi::{AbiCompression, AbiFormat, AbiResult};
use crate::common::ColorPreference;
use crate::types::{manifest::CargoManifestPath, metadata::CrateMetadata};
use crate::util;
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions cargo-near/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use strum::{EnumDiscriminants, EnumIter, EnumMessage};

pub mod abi_command;
pub mod build_command;

#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(context = near_cli_rs::GlobalContext)]
#[strum_discriminants(derive(EnumMessage, EnumIter))]
#[interactive_clap(disable_back)]
/// 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 = "build - Build a NEAR contract and optionally embed ABI"
))]
/// Build a NEAR contract and optionally embed ABI
Build(self::build_command::BuildCommand),
#[strum_discriminants(strum(message = "abi - Generates ABI for the contract"))]
/// Generates ABI for the contract
Abi(self::abi_command::AbiCommand),
}
23 changes: 3 additions & 20 deletions cargo-near/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
pub use near_cli_rs::CliResult;
use strum::{EnumDiscriminants, EnumIter, EnumMessage};

pub mod abi_command;
pub mod build_command;
pub mod commands;
mod common;
pub mod types;
mod util;
Expand All @@ -11,7 +10,7 @@ mod util;
#[interactive_clap(context = near_cli_rs::GlobalContext)]
pub struct Cmd {
#[interactive_clap(subcommand)]
opts: Opts,
pub opts: Opts,
}

#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)]
Expand All @@ -29,21 +28,5 @@ pub enum Opts {
#[interactive_clap(context = near_cli_rs::GlobalContext)]
pub struct NearArgs {
#[interactive_clap(subcommand)]
pub cmd: NearCommand,
}

#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(context = near_cli_rs::GlobalContext)]
#[strum_discriminants(derive(EnumMessage, EnumIter))]
#[interactive_clap(disable_back)]
/// 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 = "build - Build a NEAR contract and optionally embed ABI"
))]
/// Build a NEAR contract and optionally embed ABI
Build(self::build_command::BuildCommand),
#[strum_discriminants(strum(message = "abi - Generates ABI for the contract"))]
/// Generates ABI for the contract
Abi(self::abi_command::AbiCommand),
pub cmd: self::commands::NearCommand,
}
13 changes: 6 additions & 7 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ macro_rules! invoke_cargo_near {
let cargo_near::CliOpts::Near(cli_args) = cargo_near::Opts::try_parse_from($cli_opts)?;

match cli_args.cmd {
Some(cargo_near::CliNearCommand::Abi(cmd)) => {
let args = cargo_near::abi_command::AbiCommand {
Some(cargo_near::commands::CliNearCommand::Abi(cmd)) => {
let args = cargo_near::commands::abi_command::AbiCommand {
doc: cmd.doc,
compact_abi: cmd.compact_abi,
out_dir: cmd.out_dir,
manifest_path: Some(cargo_near::types::utf8_path_buf::Utf8PathBufInner(cargo_path)),
color: cmd.color,
};
cargo_near::abi_command::abi::run(args)?;
cargo_near::commands::abi_command::abi::run(args)?;
},
Some(cargo_near::CliNearCommand::Build(cmd)) => {
let args = cargo_near::build_command::BuildCommand {
Some(cargo_near::commands::CliNearCommand::Build(cmd)) => {
let args = cargo_near::commands::build_command::BuildCommand {
release: cmd.release,
embed_abi: cmd.embed_abi,
doc: cmd.doc,
Expand All @@ -65,8 +65,7 @@ macro_rules! invoke_cargo_near {
manifest_path: Some(cargo_near::types::utf8_path_buf::Utf8PathBufInner(cargo_path)),
color: cmd.color,
};
println!("### {args:?}");
cargo_near::build_command::build::run(args)?;
cargo_near::commands::build_command::build::run(args)?;
},
None => ()
}
Expand Down

0 comments on commit 69d1c88

Please sign in to comment.