diff options
Diffstat (limited to '')
| -rw-r--r-- | crates/client/src/command/mod.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/crates/client/src/command/mod.rs b/crates/client/src/command/mod.rs new file mode 100644 index 00000000..a2e75034 --- /dev/null +++ b/crates/client/src/command/mod.rs @@ -0,0 +1,56 @@ +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<String> { + 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.") + }) +} |
