always use delta and check if it exists

master
Rasmus Rosengren 2 years ago
parent c7f45b6299
commit 3ae7c26213
No known key found for this signature in database
GPG Key ID: C2ABAF65A0205874
  1. 4
      src/diff.rs
  2. 8
      src/main.rs
  3. 8
      src/opts.rs
  4. 5
      src/utils.rs

@ -4,7 +4,7 @@ use terminal_size::{terminal_size, Width};
use crate::{config::Config, utils::get_tree_files}; 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?; tokio::fs::create_dir_all(&config.install_dir).await?;
let built_files = get_tree_files(config, &config.build_dir).await?; let built_files = get_tree_files(config, &config.build_dir).await?;
let installed_files = get_tree_files(config, &config.install_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) .current_dir(workdir)
.arg(second_path) .arg(second_path)
.arg(first_path) .arg(first_path)

@ -10,6 +10,7 @@ use std::path::PathBuf;
use clap::{IntoApp, Parser}; use clap::{IntoApp, Parser};
use clap_complete::generate; use clap_complete::generate;
use directories::{ProjectDirs, UserDirs}; use directories::{ProjectDirs, UserDirs};
use utils::command_exists;
use crate::{build::build, config::Config, diff::diff, install::install, opts::Opts}; use crate::{build::build, config::Config, diff::diff, install::install, opts::Opts};
@ -51,7 +52,12 @@ async fn main() -> anyhow::Result<()> {
if opts.install { if opts.install {
install(&config).await?; install(&config).await?;
} else { } else {
diff(&config, opts.diff_command).await?; if !command_exists("delta").await {
println!("'delta' is not installed");
return Ok(());
}
diff(&config).await?;
} }
Ok(()) Ok(())

@ -24,14 +24,6 @@ pub struct Opts {
)] )]
pub repo_path: PathBuf, 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")] #[clap(long, value_name = "SHELL", help = "Generate shell completions")]
pub generate: Option<Shell>, pub generate: Option<Shell>,
} }

@ -63,3 +63,8 @@ pub async fn remove_dir_if_empty(path: &Path) -> anyhow::Result<()> {
Ok(()) Ok(())
} }
pub async fn command_exists(command: &str) -> bool {
tokio::process::Command::new("which")
.arg(&command).status().await.is_ok()
}
Loading…
Cancel
Save