refactor: move doctor command

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-08-01 17:15:58 +02:00
parent af5d0f4af5
commit 526b2b7461
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
3 changed files with 29 additions and 11 deletions

View File

@ -14,6 +14,7 @@ use cuddle_please_misc::{
use crate::{ use crate::{
config_command::{ConfigCommand, ConfigCommandHandler}, config_command::{ConfigCommand, ConfigCommandHandler},
doctor_command::DoctorCommandHandler,
gitea_command::{GiteaCommand, GiteaCommandHandler}, gitea_command::{GiteaCommand, GiteaCommandHandler},
release_command::ReleaseCommandHandler, release_command::ReleaseCommandHandler,
}; };
@ -96,7 +97,6 @@ impl Command {
ReleaseCommandHandler::new(config, git_client, gitea_client) ReleaseCommandHandler::new(config, git_client, gitea_client)
.execute(self.global.dry_run)?; .execute(self.global.dry_run)?;
} }
Some(Commands::Config { command }) => { Some(Commands::Config { command }) => {
ConfigCommandHandler::new(self.ui, config).execute(command)?; ConfigCommandHandler::new(self.ui, config).execute(command)?;
} }
@ -105,16 +105,7 @@ impl Command {
.execute(command, self.global.token.expect("token to be set").deref())?; .execute(command, self.global.token.expect("token to be set").deref())?;
} }
Some(Commands::Doctor {}) => { Some(Commands::Doctor {}) => {
match std::process::Command::new("git").arg("-v").output() { DoctorCommandHandler::new(self.ui).execute()?;
Ok(o) => {
let stdout = std::str::from_utf8(&o.stdout).unwrap_or("");
self.ui.write_str_ln(&format!("OK: {}", stdout));
}
Err(e) => {
self.ui
.write_str_ln(&format!("WARNING: git is not installed: {}", e));
}
}
} }
None => {} None => {}
} }

View File

@ -0,0 +1,26 @@
use cuddle_please_misc::DynUi;
pub struct DoctorCommandHandler {
ui: DynUi,
}
impl DoctorCommandHandler {
pub fn new(ui: DynUi) -> Self {
Self { ui }
}
pub fn execute(&self) -> anyhow::Result<()> {
match std::process::Command::new("git").arg("-v").output() {
Ok(o) => {
let stdout = std::str::from_utf8(&o.stdout).unwrap_or("");
self.ui.write_str_ln(&format!("OK: {}", stdout));
}
Err(e) => {
self.ui
.write_str_ln(&format!("WARNING: git is not installed: {}", e));
}
}
Ok(())
}
}

View File

@ -1,5 +1,6 @@
mod command; mod command;
mod config_command; mod config_command;
mod doctor_command;
mod gitea_command; mod gitea_command;
mod release_command; mod release_command;