diff --git a/src/diff.rs b/src/diff.rs index c2c4389..413d9f5 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -4,7 +4,7 @@ use terminal_size::{terminal_size, Width}; use crate::{config::Config, utils::get_tree_files}; -pub async fn diff(config: &Config, diff_command: String) -> anyhow::Result<()> { +pub async fn diff(config: &Config) -> anyhow::Result<()> { tokio::fs::create_dir_all(&config.install_dir).await?; let built_files = get_tree_files(config, &config.build_dir).await?; let installed_files = get_tree_files(config, &config.install_dir).await?; @@ -39,7 +39,7 @@ pub async fn diff(config: &Config, diff_command: String) -> anyhow::Result<()> { ) }; - let output = tokio::process::Command::new(&diff_command) + let output = tokio::process::Command::new("delta") .current_dir(workdir) .arg(second_path) .arg(first_path) diff --git a/src/main.rs b/src/main.rs index e161cbc..bd8cd2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use std::path::PathBuf; use clap::{IntoApp, Parser}; use clap_complete::generate; use directories::{ProjectDirs, UserDirs}; +use utils::command_exists; use crate::{build::build, config::Config, diff::diff, install::install, opts::Opts}; @@ -51,7 +52,12 @@ async fn main() -> anyhow::Result<()> { if opts.install { install(&config).await?; } else { - diff(&config, opts.diff_command).await?; + if !command_exists("delta").await { + println!("'delta' is not installed"); + return Ok(()); + } + + diff(&config).await?; } Ok(()) diff --git a/src/opts.rs b/src/opts.rs index a0d1d3c..a6a27c0 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -24,14 +24,6 @@ pub struct Opts { )] pub repo_path: PathBuf, - #[clap( - short, - long, - default_value = "delta", - help = "Command to execute to show diffs" - )] - pub diff_command: String, - #[clap(long, value_name = "SHELL", help = "Generate shell completions")] pub generate: Option, } diff --git a/src/utils.rs b/src/utils.rs index 170538d..5412f9a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -63,3 +63,8 @@ pub async fn remove_dir_if_empty(path: &Path) -> anyhow::Result<()> { Ok(()) } + +pub async fn command_exists(command: &str) -> bool { + tokio::process::Command::new("which") + .arg(&command).status().await.is_ok() +} \ No newline at end of file