#![doc = doc_self!()]
use std::sync::LazyLock;
use async_trait::async_trait;
use indoc::indoc;
use tap::prelude::*;
use super::{DryRunStrategy, Pm, PmHelper, Strategy};
use crate::{config::Config, error::Result, exec::Cmd};
macro_rules! doc_self {
() => {
indoc! {"
The [TexLive Package Manager](https://www.tug.org/texlive/tlmgr.html).
"}
};
}
use doc_self;
#[doc = doc_self!()]
#[derive(Debug)]
pub struct Tlmgr {
cfg: Config,
}
static STRAT_CHECK_DRY: LazyLock<Strategy> = LazyLock::new(|| Strategy {
dry_run: DryRunStrategy::with_flags(["--dry-run"]),
..Strategy::default()
});
impl Tlmgr {
#[must_use]
#[allow(missing_docs)]
pub const fn new(cfg: Config) -> Self {
Self { cfg }
}
}
#[async_trait]
impl Pm for Tlmgr {
fn name(&self) -> &'static str {
"tlmgr"
}
fn cfg(&self) -> &Config {
&self.cfg
}
async fn q(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
self.qi(kws, flags).await
}
async fn qi(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
Cmd::new(["tlmgr", "info", "--only-installed"])
.kws(kws)
.flags(flags)
.pipe(|cmd| self.run(cmd))
.await
}
async fn qk(&self, _kws: &[&str], flags: &[&str]) -> Result<()> {
self.run(Cmd::new(["tlmgr", "check", "files"]).flags(flags))
.await
}
async fn ql(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
Cmd::new(["tlmgr", "info", "--only-installed", "--list"])
.kws(kws)
.flags(flags)
.pipe(|cmd| self.run(cmd))
.await
}
async fn r(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
Cmd::new(["tlmgr", "remove"])
.kws(kws)
.flags(flags)
.pipe(|cmd| self.run_with(cmd, self.default_mode(), &STRAT_CHECK_DRY))
.await
}
async fn s(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
Cmd::new(["tlmgr", "install"])
.kws(kws)
.flags(flags)
.pipe(|cmd| self.run_with(cmd, self.default_mode(), &STRAT_CHECK_DRY))
.await
}
async fn si(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
self.run(Cmd::new(["tlmgr", "info"]).kws(kws).flags(flags))
.await
}
async fn sl(&self, _kws: &[&str], flags: &[&str]) -> Result<()> {
self.run(Cmd::new(["tlmgr", "info"]).flags(flags)).await
}
async fn ss(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
Cmd::new(["tlmgr", "search", "--global"])
.kws(kws)
.flags(flags)
.pipe(|cmd| self.run(cmd))
.await
}
async fn su(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
Cmd::new(if kws.is_empty() {
&["tlmgr", "update", "--self", "--all"][..]
} else {
&["tlmgr", "update", "--self"][..]
})
.kws(kws)
.flags(flags)
.pipe(|cmd| self.run_with(cmd, self.default_mode(), &STRAT_CHECK_DRY))
.await
}
async fn suy(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
self.su(kws, flags).await
}
async fn u(&self, kws: &[&str], flags: &[&str]) -> Result<()> {
Cmd::new(["tlmgr", "install", "--file"])
.kws(kws)
.flags(flags)
.pipe(|cmd| self.run_with(cmd, self.default_mode(), &STRAT_CHECK_DRY))
.await
}
}