Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: minor refactor and integration tests #186

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions crates/commands/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ pub mod update;
#[clap(name = "soldeer", author = "m4rio.eth", version)]
pub struct Args {
#[clap(subcommand)]
pub command: Subcommands,
pub command: Command,
}

/// The available commands for Soldeer
#[derive(Debug, Clone, Subcommand, From)]
pub enum Subcommands {
pub enum Command {
Init(init::Init),
Install(install::Install),
Update(update::Update),
Expand All @@ -27,13 +28,13 @@ pub enum Subcommands {
Version(Version),
}

/// Display the version of Soldeer
#[derive(Debug, Clone, Default, Parser)]
pub struct Version {}

fn validate_dependency(dep: &str) -> std::result::Result<String, String> {
if dep.split('~').count() != 2 {
return Err("The dependency should be in the format <DEPENDENCY>~<VERSION>".to_string());
}
Ok(dep.to_string())
}

/// Display the version of Soldeer
#[derive(Debug, Clone, Default, Parser)]
pub struct Version {}
18 changes: 9 additions & 9 deletions crates/commands/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
//! High-level commands for the Soldeer CLI
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
pub use crate::commands::{Args, Subcommands};
pub use crate::commands::{Args, Command};
use cliclack::{intro, log::step, outro, outro_cancel};
use soldeer_core::{config::Paths, Result};
use std::env;

pub mod commands;

pub async fn run(command: Subcommands) -> Result<()> {
pub async fn run(command: Command) -> Result<()> {
let paths = Paths::new()?;
match command {
Subcommands::Init(init) => {
Command::Init(init) => {
intro("🦌 Soldeer Init 🦌")?;
step("Initialize Foundry project to use Soldeer")?;
commands::init::init_command(&paths, init).await.inspect_err(|_| {
outro_cancel("An error occurred during initialization").ok();
})?;
outro("Done initializing!")?;
}
Subcommands::Install(cmd) => {
Command::Install(cmd) => {
intro("🦌 Soldeer Install 🦌")?;
commands::install::install_command(&paths, cmd).await.inspect_err(|_| {
outro_cancel("An error occurred during install").ok();
})?;
outro("Done installing!")?;
}
Subcommands::Update(cmd) => {
Command::Update(cmd) => {
intro("🦌 Soldeer Update 🦌")?;
commands::update::update_command(&paths, cmd).await.inspect_err(|_| {
outro_cancel("An error occurred during the update").ok();
})?;
outro("Done updating!")?;
}
Subcommands::Uninstall(cmd) => {
Command::Uninstall(cmd) => {
intro("🦌 Soldeer Uninstall 🦌")?;
commands::uninstall::uninstall_command(&paths, &cmd).inspect_err(|_| {
outro_cancel("An error occurred during uninstall").ok();
})?;
outro("Done uninstalling!")?;
}
Subcommands::Login(_) => {
Command::Login(_) => {
intro("🦌 Soldeer Login 🦌")?;
commands::login::login_command().await.inspect_err(|_| {
outro_cancel("An error occurred during login").ok();
})?;
outro("Done logging in!")?;
}
Subcommands::Push(cmd) => {
Command::Push(cmd) => {
intro("🦌 Soldeer Push 🦌")?;
commands::push::push_command(cmd).await.inspect_err(|_| {
outro_cancel("An error occurred during push").ok();
})?;
outro("Done!")?;
}
Subcommands::Version(_) => {
Command::Version(_) => {
const VERSION: &str = env!("CARGO_PKG_VERSION");
println!("soldeer {VERSION}");
}
Expand Down
10 changes: 5 additions & 5 deletions crates/commands/tests/tests-init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use soldeer_commands::{commands::init::Init, run, Subcommands};
use soldeer_commands::{commands::init::Init, run, Command};
use soldeer_core::{config::read_config_deps, lock::read_lockfile, utils::run_git_command};
use std::fs;
use temp_env::async_with_vars;
Expand All @@ -14,7 +14,7 @@ async fn test_init_clean() {
.await
.unwrap();
fs::write(dir.join("soldeer.toml"), "[dependencies]\n").unwrap();
let cmd: Subcommands = Init { clean: true }.into();
let cmd: Command = Init { clean: true }.into();
let res =
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd))
.await;
Expand Down Expand Up @@ -42,7 +42,7 @@ async fn test_init_no_clean() {
.await
.unwrap();
fs::write(dir.join("soldeer.toml"), "[dependencies]\n").unwrap();
let cmd: Subcommands = Init { clean: false }.into();
let cmd: Command = Init { clean: false }.into();
let res =
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd))
.await;
Expand Down Expand Up @@ -75,7 +75,7 @@ remappings_generate = false
[dependencies]
";
fs::write(dir.join("soldeer.toml"), contents).unwrap();
let cmd: Subcommands = Init { clean: true }.into();
let cmd: Command = Init { clean: true }.into();
let res =
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd))
.await;
Expand All @@ -94,7 +94,7 @@ async fn test_init_no_gitignore() {
.unwrap();
fs::remove_file(dir.join(".gitignore")).unwrap();
fs::write(dir.join("soldeer.toml"), "[dependencies]\n").unwrap();
let cmd: Subcommands = Init { clean: true }.into();
let cmd: Command = Init { clean: true }.into();
let res =
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd))
.await;
Expand Down
Loading