atuin/src/command/mod.rs

89 lines
2.1 KiB
Rust
Raw Normal View History

use clap::{CommandFactory, Subcommand};
use clap_complete::{generate, generate_to, Shell};
use eyre::Result;
2021-02-14 10:18:02 -07:00
#[cfg(feature = "client")]
mod client;
#[cfg(feature = "server")]
2021-02-14 10:18:02 -07:00
mod server;
mod init;
mod contributors;
2022-04-06 23:32:11 -06:00
#[derive(Subcommand)]
#[clap(infer_subcommands = true)]
2021-02-14 10:18:02 -07:00
pub enum AtuinCmd {
#[cfg(feature = "client")]
#[clap(flatten)]
Client(client::Cmd),
2021-02-14 10:18:02 -07:00
2022-04-06 23:32:11 -06:00
/// Start an atuin server
#[cfg(feature = "server")]
2022-04-06 23:32:11 -06:00
#[clap(subcommand)]
2021-02-14 10:18:02 -07:00
Server(server::Cmd),
/// Output shell setup
#[clap(subcommand)]
Init(init::Cmd),
/// Generate a UUID
Uuid,
Contributors,
/// Generate shell completions
GenCompletions {
/// Set the shell for generating completions
#[clap(long, short)]
shell: Shell,
/// Set the output directory
#[clap(long, short)]
out_dir: Option<String>,
},
2021-02-14 10:18:02 -07:00
}
impl AtuinCmd {
pub fn run(self) -> Result<()> {
match self {
#[cfg(feature = "client")]
Self::Client(client) => client.run(),
#[cfg(feature = "server")]
Self::Server(server) => server.run(),
Self::Contributors => {
contributors::run();
Ok(())
}
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(())
}
}
}
}