2022-09-25 04:15:33 -06:00
|
|
|
use clap::{CommandFactory, Subcommand};
|
|
|
|
use clap_complete::{generate, generate_to, Shell};
|
2022-04-21 03:12:56 -06:00
|
|
|
use eyre::Result;
|
2021-02-14 10:18:02 -07:00
|
|
|
|
2022-05-12 23:57:27 -06:00
|
|
|
#[cfg(feature = "client")]
|
2022-04-21 03:12:56 -06:00
|
|
|
mod client;
|
2022-04-22 14:14:23 -06:00
|
|
|
|
|
|
|
#[cfg(feature = "server")]
|
2021-02-14 10:18:02 -07:00
|
|
|
mod server;
|
|
|
|
|
2022-09-25 04:15:33 -06:00
|
|
|
mod init;
|
|
|
|
|
2022-10-04 22:56:49 -06:00
|
|
|
mod contributors;
|
|
|
|
|
2022-04-06 23:32:11 -06:00
|
|
|
#[derive(Subcommand)]
|
2022-10-18 02:50:22 -06:00
|
|
|
#[command(infer_subcommands = true)]
|
2021-02-14 10:18:02 -07:00
|
|
|
pub enum AtuinCmd {
|
2022-05-12 23:57:27 -06:00
|
|
|
#[cfg(feature = "client")]
|
2022-10-18 02:50:22 -06:00
|
|
|
#[command(flatten)]
|
2022-04-21 03:12:56 -06:00
|
|
|
Client(client::Cmd),
|
2021-02-14 10:18:02 -07:00
|
|
|
|
2022-04-06 23:32:11 -06:00
|
|
|
/// Start an atuin server
|
2022-04-22 14:14:23 -06:00
|
|
|
#[cfg(feature = "server")]
|
2022-10-18 02:50:22 -06:00
|
|
|
#[command(subcommand)]
|
2021-02-14 10:18:02 -07:00
|
|
|
Server(server::Cmd),
|
2022-09-25 04:15:33 -06:00
|
|
|
|
|
|
|
/// Output shell setup
|
2022-10-18 02:50:22 -06:00
|
|
|
#[command(subcommand)]
|
2022-09-25 04:15:33 -06:00
|
|
|
Init(init::Cmd),
|
|
|
|
|
|
|
|
/// Generate a UUID
|
|
|
|
Uuid,
|
|
|
|
|
2022-10-04 22:56:49 -06:00
|
|
|
Contributors,
|
|
|
|
|
2022-09-25 04:15:33 -06:00
|
|
|
/// Generate shell completions
|
|
|
|
GenCompletions {
|
|
|
|
/// Set the shell for generating completions
|
2022-10-18 02:50:22 -06:00
|
|
|
#[arg(long, short)]
|
2022-09-25 04:15:33 -06:00
|
|
|
shell: Shell,
|
|
|
|
|
|
|
|
/// Set the output directory
|
2022-10-18 02:50:22 -06:00
|
|
|
#[arg(long, short)]
|
2022-09-25 04:15:33 -06:00
|
|
|
out_dir: Option<String>,
|
|
|
|
},
|
2021-02-14 10:18:02 -07:00
|
|
|
}
|
2021-02-14 11:00:41 -07:00
|
|
|
|
|
|
|
impl AtuinCmd {
|
2022-05-09 00:46:52 -06:00
|
|
|
pub fn run(self) -> Result<()> {
|
2021-02-14 11:00:41 -07:00
|
|
|
match self {
|
2022-05-12 23:57:27 -06:00
|
|
|
#[cfg(feature = "client")]
|
2022-05-09 00:46:52 -06:00
|
|
|
Self::Client(client) => client.run(),
|
2022-04-22 14:14:23 -06:00
|
|
|
#[cfg(feature = "server")]
|
2022-05-09 00:46:52 -06:00
|
|
|
Self::Server(server) => server.run(),
|
2022-10-04 22:56:49 -06:00
|
|
|
Self::Contributors => {
|
|
|
|
contributors::run();
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-09-25 04:15:33 -06:00
|
|
|
Self::Init(init) => {
|
|
|
|
init.run();
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
Self::Uuid => {
|
|
|
|
println!("{}", atuin_common::utils::uuid_v4());
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
Self::GenCompletions { shell, out_dir } => {
|
|
|
|
let mut cli = crate::Atuin::command();
|
|
|
|
|
|
|
|
match out_dir {
|
|
|
|
Some(out_dir) => {
|
|
|
|
generate_to(shell, &mut cli, env!("CARGO_PKG_NAME"), &out_dir)?;
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
generate(
|
|
|
|
shell,
|
|
|
|
&mut cli,
|
|
|
|
env!("CARGO_PKG_NAME"),
|
|
|
|
&mut std::io::stdout(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-02-14 11:00:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|