aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/history.rs41
-rw-r--r--src/command/import.rs30
-rw-r--r--src/command/init.rs10
-rw-r--r--src/command/login.rs14
-rw-r--r--src/command/mod.rs102
-rw-r--r--src/command/register.rs13
-rw-r--r--src/command/server.rs16
-rw-r--r--src/command/stats.rs15
8 files changed, 122 insertions, 119 deletions
diff --git a/src/command/history.rs b/src/command/history.rs
index b644b9ac..6eaa6407 100644
--- a/src/command/history.rs
+++ b/src/command/history.rs
@@ -2,8 +2,8 @@ use std::env;
use std::io::Write;
use std::time::Duration;
+use clap::Subcommand;
use eyre::Result;
-use structopt::StructOpt;
use tabwriter::TabWriter;
use atuin_client::database::Database;
@@ -11,51 +11,42 @@ use atuin_client::history::History;
use atuin_client::settings::Settings;
use atuin_client::sync;
-#[derive(StructOpt)]
+#[derive(Subcommand)]
+#[clap(infer_subcommands = true)]
pub enum Cmd {
- #[structopt(
- about="begins a new command in the history",
- aliases=&["s", "st", "sta", "star"],
- )]
+ /// Begins a new command in the history
Start { command: Vec<String> },
- #[structopt(
- about="finishes a new command in the history (adds time, exit code)",
- aliases=&["e", "en"],
- )]
+ /// Finishes a new command in the history (adds time, exit code)
End {
id: String,
- #[structopt(long, short)]
+ #[clap(long, short)]
exit: i64,
},
- #[structopt(
- about="list all items in history",
- aliases=&["l", "li", "lis"],
- )]
+ /// List all items in history
List {
- #[structopt(long, short)]
+ #[clap(long, short)]
cwd: bool,
- #[structopt(long, short)]
+ #[clap(long, short)]
session: bool,
- #[structopt(long, short)]
+ #[clap(long)]
human: bool,
- #[structopt(long, help = "Show only the text of the command")]
+ /// Show only the text of the command
+ #[clap(long)]
cmd_only: bool,
},
- #[structopt(
- about="get the last command ran",
- aliases=&["la", "las"],
- )]
+ /// Get the last command ran
Last {
- #[structopt(long, short)]
+ #[clap(long)]
human: bool,
- #[structopt(long, help = "Show only the text of the command")]
+ /// Show only the text of the command
+ #[clap(long)]
cmd_only: bool,
},
}
diff --git a/src/command/import.rs b/src/command/import.rs
index 166fcd3e..7e2f5c5c 100644
--- a/src/command/import.rs
+++ b/src/command/import.rs
@@ -1,44 +1,30 @@
use std::{env, path::PathBuf};
use atuin_client::import::fish::Fish;
+use clap::Parser;
use eyre::{eyre, Result};
-use structopt::StructOpt;
use atuin_client::import::{bash::Bash, zsh::Zsh};
use atuin_client::{database::Database, import::Importer};
use atuin_client::{history::History, import::resh::Resh};
use indicatif::ProgressBar;
-#[derive(StructOpt)]
+#[derive(Parser)]
+#[clap(infer_subcommands = true)]
pub enum Cmd {
- #[structopt(
- about="import history for the current shell",
- aliases=&["a", "au", "aut"],
- )]
+ /// Import history for the current shell
Auto,
- #[structopt(
- about="import history from the zsh history file",
- aliases=&["z", "zs"],
- )]
+ /// Import history from the zsh history file
Zsh,
- #[structopt(
- about="import history from the bash history file",
- aliases=&["b", "ba", "bas"],
- )]
+ /// Import history from the bash history file
Bash,
- #[structopt(
- about="import history from the resh history file",
- aliases=&["r", "re", "res"],
- )]
+ /// Import history from the resh history file
Resh,
- #[structopt(
- about="import history from the fish history file",
- aliases=&["f", "fi", "fis"],
- )]
+ /// Import history from the fish history file
Fish,
}
diff --git a/src/command/init.rs b/src/command/init.rs
index 5d3ffed2..37453f93 100644
--- a/src/command/init.rs
+++ b/src/command/init.rs
@@ -1,12 +1,12 @@
-use structopt::StructOpt;
+use clap::Parser;
-#[derive(StructOpt)]
+#[derive(Parser)]
pub enum Cmd {
- #[structopt(about = "zsh setup")]
+ /// Zsh setup
Zsh,
- #[structopt(about = "bash setup")]
+ /// Bash setup
Bash,
- #[structopt(about = "fish setup")]
+ /// Fish setup
Fish,
}
diff --git a/src/command/login.rs b/src/command/login.rs
index c33fa5e1..fe442bc1 100644
--- a/src/command/login.rs
+++ b/src/command/login.rs
@@ -2,23 +2,25 @@ use std::borrow::Cow;
use std::io;
use atuin_common::api::LoginRequest;
+use clap::AppSettings;
+use clap::Parser;
use eyre::Result;
-use structopt::StructOpt;
use tokio::{fs::File, io::AsyncWriteExt};
use atuin_client::api_client;
use atuin_client::settings::Settings;
-#[derive(StructOpt)]
-#[structopt(setting(structopt::clap::AppSettings::DeriveDisplayOrder))]
+#[derive(Parser)]
+#[clap(setting(AppSettings::DeriveDisplayOrder))]
pub struct Cmd {
- #[structopt(long, short)]
+ #[clap(long, short)]
pub username: Option<String>,
- #[structopt(long, short)]
+ #[clap(long, short)]
pub password: Option<String>,
- #[structopt(long, short, help = "the encryption key for your account")]
+ /// The encryption key for your account
+ #[clap(long, short)]
pub key: Option<String>,
}
diff --git a/src/command/mod.rs b/src/command/mod.rs
index 4864a8d6..6873c587 100644
--- a/src/command/mod.rs
+++ b/src/command/mod.rs
@@ -1,8 +1,10 @@
use std::path::PathBuf;
+use clap::CommandFactory;
+use clap::Subcommand;
+use clap_complete::Shell;
+use clap_complete::{generate, generate_to};
use eyre::{Result, WrapErr};
-use structopt::clap::Shell;
-use structopt::StructOpt;
use atuin_client::database::Sqlite;
use atuin_client::settings::Settings as ClientSettings;
@@ -21,86 +23,101 @@ mod server;
mod stats;
mod sync;
-#[derive(StructOpt)]
+#[derive(Subcommand)]
+#[clap(infer_subcommands = true)]
pub enum AtuinCmd {
- #[structopt(
- about="manipulate shell history",
- aliases=&["h", "hi", "his", "hist", "histo", "histor"],
- )]
+ /// Manipulate shell history
+ #[clap(subcommand)]
History(history::Cmd),
- #[structopt(about = "import shell history from file")]
+ /// Import shell history from file
+ #[clap(subcommand)]
Import(import::Cmd),
- #[structopt(about = "start an atuin server")]
+ /// Start an atuin server
+ #[clap(subcommand)]
Server(server::Cmd),
- #[structopt(about = "calculate statistics for your history")]
+ /// Calculate statistics for your history
+ #[clap(subcommand)]
Stats(stats::Cmd),
- #[structopt(about = "output shell setup")]
+ /// Output shell setup
+ #[clap(subcommand)]
Init(init::Cmd),
- #[structopt(about = "generates a UUID")]
+ /// Generate a UUID
Uuid,
- #[structopt(about = "interactive history search")]
+ /// Interactive history search
Search {
- #[structopt(long, short, help = "filter search result by directory")]
+ /// Filter search result by directory
+ #[clap(long, short)]
cwd: Option<String>,
- #[structopt(long = "exclude-cwd", help = "exclude directory from results")]
+ /// Exclude directory from results
+ #[clap(long = "exclude-cwd")]
exclude_cwd: Option<String>,
- #[structopt(long, short, help = "filter search result by exit code")]
+ /// Filter search result by exit code
+ #[clap(long, short)]
exit: Option<i64>,
- #[structopt(long = "exclude-exit", help = "exclude results with this exit code")]
+ /// Exclude results with this exit code
+ #[clap(long = "exclude-exit")]
exclude_exit: Option<i64>,
- #[structopt(long, short, help = "only include results added before this date")]
+ /// Only include results added before this date
+ #[clap(long, short)]
before: Option<String>,
- #[structopt(long, help = "only include results after this date")]
+ /// Only include results after this date
+ #[clap(long)]
after: Option<String>,
- #[structopt(long, short, help = "open interactive search UI")]
+ /// Open interactive search UI
+ #[clap(long, short)]
interactive: bool,
- #[structopt(long, short, help = "use human-readable formatting for time")]
+ /// Use human-readable formatting for time
+ #[clap(long)]
human: bool,
query: Vec<String>,
- #[structopt(long, help = "Show only the text of the command")]
+ /// Show only the text of the command
+ #[clap(long)]
cmd_only: bool,
},
- #[structopt(about = "sync with the configured server")]
+ /// Sync with the configured server
Sync {
- #[structopt(long, short, help = "force re-download everything")]
+ /// Force re-download everything
+ #[clap(long, short)]
force: bool,
},
- #[structopt(about = "login to the configured server")]
+ /// Login to the configured server
Login(login::Cmd),
- #[structopt(about = "log out")]
+ /// Log out
Logout,
- #[structopt(about = "register with the configured server")]
+ /// Register with the configured server
Register(register::Cmd),
- #[structopt(about = "print the encryption key for transfer to another machine")]
+ /// Print the encryption key for transfer to another machine
Key,
- #[structopt(about = "generate shell completions")]
+ /// Generate shell completions
GenCompletions {
- #[structopt(long, short, help = "set the shell for generating completions")]
+ /// Set the shell for generating completions
+ #[clap(long, short)]
shell: Shell,
- #[structopt(long, short, help = "set the output directory")]
- out_dir: String,
+ /// Set the output directory
+ #[clap(long, short)]
+ out_dir: Option<String>,
},
}
@@ -172,11 +189,22 @@ impl AtuinCmd {
Ok(())
}
Self::GenCompletions { shell, out_dir } => {
- AtuinCmd::clap().gen_completions(env!("CARGO_PKG_NAME"), shell, &out_dir);
- println!(
- "Shell completion for {} is generated in {:?}",
- 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(())
}
}
diff --git a/src/command/register.rs b/src/command/register.rs
index 20ad1327..46f4a65d 100644
--- a/src/command/register.rs
+++ b/src/command/register.rs
@@ -1,20 +1,21 @@
+use clap::AppSettings;
+use clap::Parser;
use eyre::Result;
-use structopt::StructOpt;
use tokio::{fs::File, io::AsyncWriteExt};
use atuin_client::api_client;
use atuin_client::settings::Settings;
-#[derive(StructOpt)]
-#[structopt(setting(structopt::clap::AppSettings::DeriveDisplayOrder))]
+#[derive(Parser)]
+#[clap(setting(AppSettings::DeriveDisplayOrder))]
pub struct Cmd {
- #[structopt(long, short)]
+ #[clap(long, short)]
pub username: Option<String>,
- #[structopt(long, short)]
+ #[clap(long, short)]
pub email: Option<String>,
- #[structopt(long, short)]
+ #[clap(long, short)]
pub password: Option<String>,
}
diff --git a/src/command/server.rs b/src/command/server.rs
index ad7addfd..6047e5bf 100644
--- a/src/command/server.rs
+++ b/src/command/server.rs
@@ -1,20 +1,20 @@
+use clap::Parser;
use eyre::Result;
-use structopt::StructOpt;
use atuin_server::launch;
use atuin_server::settings::Settings;
-#[derive(StructOpt)]
+#[derive(Parser)]
+#[clap(infer_subcommands = true)]
pub enum Cmd {
- #[structopt(
- about="starts the server",
- aliases=&["s", "st", "sta", "star"],
- )]
+ /// Start the server
Start {
- #[structopt(help = "specify the host address to bind", long, short)]
+ /// The host address to bind
+ #[clap(long, short)]
host: Option<String>,
- #[structopt(help = "specify the port to bind", long, short)]
+ /// The port to bind
+ #[clap(long, short)]
port: Option<u16>,
},
}
diff --git a/src/command/stats.rs b/src/command/stats.rs
index 742202ae..d7bddc82 100644
--- a/src/command/stats.rs
+++ b/src/command/stats.rs
@@ -4,26 +4,21 @@ use chrono::prelude::*;
use chrono::Duration;
use chrono_english::parse_date_string;
+use clap::Parser;
use cli_table::{format::Justify, print_stdout, Cell, Style, Table};
use eyre::{eyre, Result};
-use structopt::StructOpt;
use atuin_client::database::Database;
use atuin_client::history::History;
use atuin_client::settings::Settings;
-#[derive(StructOpt)]
+#[derive(Parser)]
+#[clap(infer_subcommands = true)]
pub enum Cmd {
- #[structopt(
- about="compute statistics for all of time",
- aliases=&["d", "da"],
- )]
+ /// Compute statistics for all of time
All,
- #[structopt(
- about="compute statistics for a single day",
- aliases=&["d", "da"],
- )]
+ /// Compute statistics for a single day
Day { words: Vec<String> },
}