Skip to content

Commit

Permalink
refactor: organize tools in separate mods
Browse files Browse the repository at this point in the history
  • Loading branch information
harshdoesdev committed Oct 19, 2024
1 parent 13357bf commit 97eff1e
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::version_manager::VersionInfo;
use serde::Deserialize;
use shuru::{
error::{ConfigValidationError, Error},
version_manager::{deserialize_versions, VersionedCommand},
tools::version_manager::{deserialize_versions, VersionInfo, VersionedCommand},
};
use std::collections::HashMap;

Expand Down
8 changes: 1 addition & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ use thiserror::Error;

#[derive(Debug, Error)]
pub enum ConfigValidationError {
#[error("Invalid command name: '{0}'. Reason: {1}")]
CommandNameValidationError(String, String),

#[error("Command cannot be empty for task: '{0}'.")]
EmptyCommandError(String),

Expand All @@ -15,7 +12,7 @@ pub enum ConfigValidationError {
#[derive(Debug, Error)]
pub enum VersionManagerError {
#[error("Unable to find home directory")]
UnableHomeDirectory {},
UnableHomeDirectory,

#[error("Failed to download version from '{url}' | {source}")]
DownloadError {
Expand Down Expand Up @@ -100,9 +97,6 @@ pub enum Error {
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),

#[error("HTTP error: {0}")]
HttpError(#[from] reqwest::Error),

#[error("Unable to find home directory.")]
HomeDirectoryNotFound,

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ pub mod commands;
pub mod error;
pub mod util;

pub mod command_runner;
pub mod tools;

pub mod config;
pub mod version_manager;
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use shuru::{command_runner::CommandRunner, commands, config::Config, error::Error};
use shuru::{commands, config::Config, error::Error, tools::task_runner::TaskRunner};

#[derive(Parser)]
#[clap(version, about = "Shuru task runner", long_about = None)]
Expand Down Expand Up @@ -61,7 +61,7 @@ fn run() -> Result<std::process::ExitStatus, Error> {
return commands::clear_cache();
}

let runner = CommandRunner::new(config);
let runner = TaskRunner::new(config);

match cli.command {
Some(command_name) => runner.run_command(&command_name),
Expand Down
2 changes: 2 additions & 0 deletions src/tools/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod task_runner;
pub mod version_manager;
6 changes: 3 additions & 3 deletions src/command_runner.rs → src/tools/task_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use shuru::{
error::Error,
};

pub struct CommandRunner {
pub struct TaskRunner {
config: Config,
}

impl CommandRunner {
impl TaskRunner {
pub fn new(config: Config) -> Self {
CommandRunner { config }
TaskRunner { config }
}

fn find_task(&self, name: &str) -> Result<&TaskConfig, Error> {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use shuru::{
error::{Error, VersionManagerError},
version_manager::{VersionInfo, VersionManager},
tools::version_manager::{VersionInfo, VersionManager},
};

#[derive(Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::process::{Command, Stdio};

use shuru::{
error::{Error, VersionManagerError},
version_manager::{VersionInfo, VersionManager},
tools::version_manager::{VersionInfo, VersionManager},
};

#[derive(Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde::Deserialize;
use shuru::version_manager::{NodeVersionManager, PythonVersionManager, ShuruVersionManager};
use shuru::tools::version_manager::{
NodeVersionManager, PythonVersionManager, ShuruVersionManager,
};
use std::collections::HashMap;

#[derive(Debug, Hash, Eq, PartialEq, Deserialize)]
Expand Down

0 comments on commit 97eff1e

Please sign in to comment.