mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-23 00:34:20 +01:00
Allow stateless commands to be run without config/database (#544)
* Allow stateless commands to be run without config/database Fixes an issue where gen-completions fails trying to create a config directory in restrained build environments/distribution. * move non-db commands up to core subcommands * re-add lost lines * re-add lost lines Co-authored-by: Conrad Ludgate <conrad.ludgate@truelayer.com>
This commit is contained in:
parent
41eed3f6a1
commit
045c87fbcd
@ -1,18 +1,15 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::{CommandFactory, Subcommand};
|
use clap::Subcommand;
|
||||||
use clap_complete::{generate, generate_to, Shell};
|
|
||||||
use eyre::{Result, WrapErr};
|
use eyre::{Result, WrapErr};
|
||||||
|
|
||||||
use atuin_client::{database::Sqlite, settings::Settings};
|
use atuin_client::{database::Sqlite, settings::Settings};
|
||||||
use atuin_common::utils::uuid_v4;
|
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
mod sync;
|
mod sync;
|
||||||
|
|
||||||
mod history;
|
mod history;
|
||||||
mod import;
|
mod import;
|
||||||
mod init;
|
|
||||||
mod search;
|
mod search;
|
||||||
mod stats;
|
mod stats;
|
||||||
|
|
||||||
@ -30,27 +27,9 @@ pub enum Cmd {
|
|||||||
/// Calculate statistics for your history
|
/// Calculate statistics for your history
|
||||||
Stats(stats::Cmd),
|
Stats(stats::Cmd),
|
||||||
|
|
||||||
/// Output shell setup
|
|
||||||
#[clap(subcommand)]
|
|
||||||
Init(init::Cmd),
|
|
||||||
|
|
||||||
/// Generate a UUID
|
|
||||||
Uuid,
|
|
||||||
|
|
||||||
/// Interactive history search
|
/// Interactive history search
|
||||||
Search(search::Cmd),
|
Search(search::Cmd),
|
||||||
|
|
||||||
/// 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>,
|
|
||||||
},
|
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
#[clap(flatten)]
|
#[clap(flatten)]
|
||||||
Sync(sync::Cmd),
|
Sync(sync::Cmd),
|
||||||
@ -70,34 +49,7 @@ impl Cmd {
|
|||||||
Self::History(history) => history.run(&settings, &mut db).await,
|
Self::History(history) => history.run(&settings, &mut db).await,
|
||||||
Self::Import(import) => import.run(&mut db).await,
|
Self::Import(import) => import.run(&mut db).await,
|
||||||
Self::Stats(stats) => stats.run(&mut db, &settings).await,
|
Self::Stats(stats) => stats.run(&mut db, &settings).await,
|
||||||
Self::Init(init) => {
|
|
||||||
init.run();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Self::Search(search) => search.run(&mut db, &settings).await,
|
Self::Search(search) => search.run(&mut db, &settings).await,
|
||||||
Self::Uuid => {
|
|
||||||
println!("{}", 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(())
|
|
||||||
}
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
Self::Sync(sync) => sync.run(settings, &mut db).await,
|
Self::Sync(sync) => sync.run(settings, &mut db).await,
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,17 @@ pub enum Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init_zsh() {
|
fn init_zsh() {
|
||||||
let full = include_str!("../../shell/atuin.zsh");
|
let full = include_str!("../shell/atuin.zsh");
|
||||||
println!("{}", full);
|
println!("{}", full);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_bash() {
|
fn init_bash() {
|
||||||
let full = include_str!("../../shell/atuin.bash");
|
let full = include_str!("../shell/atuin.bash");
|
||||||
println!("{}", full);
|
println!("{}", full);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_fish() {
|
fn init_fish() {
|
||||||
let full = include_str!("../../shell/atuin.fish");
|
let full = include_str!("../shell/atuin.fish");
|
||||||
println!("{}", full);
|
println!("{}", full);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
use clap::Subcommand;
|
use clap::{CommandFactory, Subcommand};
|
||||||
|
use clap_complete::{generate, generate_to, Shell};
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
@ -7,6 +8,8 @@ mod client;
|
|||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
mod server;
|
mod server;
|
||||||
|
|
||||||
|
mod init;
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
#[clap(infer_subcommands = true)]
|
#[clap(infer_subcommands = true)]
|
||||||
pub enum AtuinCmd {
|
pub enum AtuinCmd {
|
||||||
@ -18,6 +21,24 @@ pub enum AtuinCmd {
|
|||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
Server(server::Cmd),
|
Server(server::Cmd),
|
||||||
|
|
||||||
|
/// Output shell setup
|
||||||
|
#[clap(subcommand)]
|
||||||
|
Init(init::Cmd),
|
||||||
|
|
||||||
|
/// Generate a UUID
|
||||||
|
Uuid,
|
||||||
|
|
||||||
|
/// 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>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AtuinCmd {
|
impl AtuinCmd {
|
||||||
@ -27,6 +48,33 @@ impl AtuinCmd {
|
|||||||
Self::Client(client) => client.run(),
|
Self::Client(client) => client.run(),
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
Self::Server(server) => server.run(),
|
Self::Server(server) => server.run(),
|
||||||
|
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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user