use clap::Subcommand; use eyre::Result; #[cfg(not(windows))] use rustix::{fs::Mode, process::umask}; mod client; mod contributors; mod gen_completions; #[derive(Subcommand)] #[command(infer_subcommands = true)] pub(crate) enum AtuinCmd { #[command(flatten)] Client(client::Cmd), /// Generate a UUID Uuid, Contributors, /// Generate shell completions GenCompletions(gen_completions::Cmd), } impl AtuinCmd { pub(crate) fn run(self) -> Result<()> { #[cfg(not(windows))] { // set umask before we potentially open/create files // or in other words, 077. Do not allow any access to any other user let mode = Mode::RWXG | Mode::RWXO; umask(mode); } match self { Self::Client(client) => client.run(), Self::Contributors => { contributors::run(); Ok(()) } Self::Uuid => { println!("{}", turtle_common::utils::uuid_v7().as_simple()); Ok(()) } Self::GenCompletions(gen_completions) => gen_completions.run(), } } } pub(crate) fn current_session() -> Result { std::env::var("ATUIN_SESSION").map_err(|_| { eyre::eyre!("Failed to find $ATUIN_SESSION in the environment. Check that you have correctly set up your shell.") }) }