add tldr and base

This commit is contained in:
2022-12-17 21:51:41 +01:00
commit 6dc747f8b0
13 changed files with 764 additions and 0 deletions

32
crates/tldr/src/update.rs Normal file
View File

@@ -0,0 +1,32 @@
pub struct Update;
impl util::Cmd for Update {
fn cmd() -> eyre::Result<clap::Command> {
Ok(clap::Command::new("update"))
}
fn exec(_: &clap::ArgMatches) -> eyre::Result<()> {
let cache_dir =
dirs::cache_dir().ok_or(eyre::anyhow!("could not find a valid cache dir"))?;
let mut tldr_cache_dir = cache_dir.clone();
tldr_cache_dir.push("kah-toolkit/tldr/store/");
std::fs::remove_dir_all(&tldr_cache_dir)?;
std::fs::create_dir_all(&tldr_cache_dir)?;
util::shell::run(
format!(
"gh repo clone tldr-pages/tldr {}",
&tldr_cache_dir
.to_str()
.ok_or(eyre::anyhow!("pathstring contains non ascii-characters"))?
)
.split(" ")
.collect::<Vec<&str>>()
.as_slice(),
)?;
Ok(())
}
}