use std::sync::Arc;
use clap::Subcommand;
use eyre::Result;
use crate::config::Config;
mod activate;
mod envrc;
mod exec;
#[derive(Debug, clap::Args)]
#[clap(hide = true, verbatim_doc_comment)]
pub struct Direnv {
#[clap(subcommand)]
command: Option<Commands>,
}
#[derive(Debug, Subcommand)]
enum Commands {
Activate(activate::DirenvActivate),
Envrc(envrc::Envrc),
Exec(exec::DirenvExec),
}
impl Commands {
pub async fn run(self, config: &Arc<Config>) -> Result<()> {
match self {
Self::Activate(cmd) => cmd.run().await,
Self::Envrc(cmd) => cmd.run(config).await,
Self::Exec(cmd) => cmd.run(config).await,
}
}
}
impl Direnv {
pub async fn run(self) -> Result<()> {
let config = Config::get().await?;
let cmd = self
.command
.unwrap_or(Commands::Activate(activate::DirenvActivate {}));
cmd.run(&config).await
}
}