1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Internal subcommands, not for direct use by users.
use std::sync::Arc;
use atuin_client::settings::Settings;
use atuin_common::logs::LogConfig;
use crate::i18n::fl;
#[derive(clap::Subcommand, Debug)]
pub enum Cmd {
PrepareSearchIndex,
#[command(
about = fl!("cmd-__internal-pty-proxy-active"),
long_about = fl!("cmd-__internal-pty-proxy-active", "long")
)]
PtyProxyActive,
}
impl Cmd {
/// Run this command.
///
/// If the command was able to be handled synchronously, this method returns [`None`].
/// Otherwise, it returns an async function that, when called, will run the command.
pub fn run(&self) -> Option<impl AsyncFnOnce(Settings) -> eyre::Result<()> + use<>> {
match self {
Self::PrepareSearchIndex => {
Some(async |settings| super::search::prepare_index(&Arc::new(settings)).await)
}
Self::PtyProxyActive => {
#[cfg(all(unix, feature = "pty-proxy"))]
let is_proxy_child = atuin_pty_proxy::is_pty_proxy_child();
#[cfg(not(all(unix, feature = "pty-proxy")))]
let is_proxy_child = false;
println!("{}", u8::from(is_proxy_child));
None
}
}
}
pub fn log_config(&self) -> Option<LogConfig> {
match self {
// These commands are called from the shell hooks with no stderr; there's no point in
// initializing logging. Also, commands that are handled synchronously
// (pty-proxy-active) are run before logging is even initialized.
Self::PrepareSearchIndex | Self::PtyProxyActive => None,
}
}
}