Update to clap 3.1.x (#289)

This commit is contained in:
Jamie Quigley 2022-04-07 06:32:11 +01:00 committed by GitHub
parent e8f7aaccef
commit f861893293
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 183 additions and 180 deletions

104
Cargo.lock generated
View file

@ -28,15 +28,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.52" version = "0.1.52"
@ -79,6 +70,8 @@ dependencies = [
"base64", "base64",
"chrono", "chrono",
"chrono-english", "chrono-english",
"clap",
"clap_complete",
"cli-table", "cli-table",
"crossbeam-channel", "crossbeam-channel",
"directories", "directories",
@ -91,7 +84,6 @@ dependencies = [
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"structopt",
"tabwriter", "tabwriter",
"termion", "termion",
"tokio", "tokio",
@ -317,17 +309,41 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.34.0" version = "3.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" checksum = "71c47df61d9e16dc010b55dba1952a57d8c215dbb533fd13cdd13369aac73b1c"
dependencies = [ dependencies = [
"ansi_term",
"atty", "atty",
"bitflags", "bitflags",
"clap_derive",
"indexmap",
"lazy_static",
"os_str_bytes",
"strsim", "strsim",
"termcolor",
"textwrap", "textwrap",
"unicode-width", ]
"vec_map",
[[package]]
name = "clap_complete"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df6f3613c0a3cddfd78b41b10203eb322cb29b600cbdf808a7d3db95691b8e25"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "3.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1"
dependencies = [
"heck 0.4.0",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
] ]
[[package]] [[package]]
@ -864,6 +880,12 @@ dependencies = [
"unicode-segmentation", "unicode-segmentation",
] ]
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.19" version = "0.1.19"
@ -1373,6 +1395,15 @@ dependencies = [
"hashbrown 0.9.1", "hashbrown 0.9.1",
] ]
[[package]]
name = "os_str_bytes"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.11.2" version = "0.11.2"
@ -2189,7 +2220,7 @@ checksum = "eee35713129561f5e55c554bba1c378e2a7e67f81257b7311183de98c50e6f94"
dependencies = [ dependencies = [
"dotenv", "dotenv",
"either", "either",
"heck", "heck 0.3.3",
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2223,33 +2254,9 @@ dependencies = [
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.8.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "structopt"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
dependencies = [
"clap",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "subtle" name = "subtle"
@ -2324,12 +2331,9 @@ dependencies = [
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.11.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
dependencies = [
"unicode-width",
]
[[package]] [[package]]
name = "thiserror" name = "thiserror"
@ -2655,12 +2659,6 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"

View file

@ -38,7 +38,6 @@ log = "0.4"
pretty_env_logger = "0.4" pretty_env_logger = "0.4"
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }
eyre = "0.6" eyre = "0.6"
structopt = "0.3"
directories = "3" directories = "3"
indicatif = "0.16.2" indicatif = "0.16.2"
serde_derive = "1.0.125" serde_derive = "1.0.125"
@ -56,6 +55,8 @@ base64 = "0.13.0"
humantime = "2.1.0" humantime = "2.1.0"
tabwriter = "1.2.1" tabwriter = "1.2.1"
crossbeam-channel = "0.5.1" crossbeam-channel = "0.5.1"
clap = { version = "3.1.8", features = ["derive"] }
clap_complete = "3.1.1"
[profile.release] [profile.release]
lto = "fat" lto = "fat"

View file

@ -2,8 +2,8 @@ use std::env;
use std::io::Write; use std::io::Write;
use std::time::Duration; use std::time::Duration;
use clap::Subcommand;
use eyre::Result; use eyre::Result;
use structopt::StructOpt;
use tabwriter::TabWriter; use tabwriter::TabWriter;
use atuin_client::database::Database; use atuin_client::database::Database;
@ -11,51 +11,42 @@ use atuin_client::history::History;
use atuin_client::settings::Settings; use atuin_client::settings::Settings;
use atuin_client::sync; use atuin_client::sync;
#[derive(StructOpt)] #[derive(Subcommand)]
#[clap(infer_subcommands = true)]
pub enum Cmd { pub enum Cmd {
#[structopt( /// Begins a new command in the history
about="begins a new command in the history",
aliases=&["s", "st", "sta", "star"],
)]
Start { command: Vec<String> }, Start { command: Vec<String> },
#[structopt( /// Finishes a new command in the history (adds time, exit code)
about="finishes a new command in the history (adds time, exit code)",
aliases=&["e", "en"],
)]
End { End {
id: String, id: String,
#[structopt(long, short)] #[clap(long, short)]
exit: i64, exit: i64,
}, },
#[structopt( /// List all items in history
about="list all items in history",
aliases=&["l", "li", "lis"],
)]
List { List {
#[structopt(long, short)] #[clap(long, short)]
cwd: bool, cwd: bool,
#[structopt(long, short)] #[clap(long, short)]
session: bool, session: bool,
#[structopt(long, short)] #[clap(long)]
human: bool, human: bool,
#[structopt(long, help = "Show only the text of the command")] /// Show only the text of the command
#[clap(long)]
cmd_only: bool, cmd_only: bool,
}, },
#[structopt( /// Get the last command ran
about="get the last command ran",
aliases=&["la", "las"],
)]
Last { Last {
#[structopt(long, short)] #[clap(long)]
human: bool, human: bool,
#[structopt(long, help = "Show only the text of the command")] /// Show only the text of the command
#[clap(long)]
cmd_only: bool, cmd_only: bool,
}, },
} }

View file

@ -1,44 +1,30 @@
use std::{env, path::PathBuf}; use std::{env, path::PathBuf};
use atuin_client::import::fish::Fish; use atuin_client::import::fish::Fish;
use clap::Parser;
use eyre::{eyre, Result}; use eyre::{eyre, Result};
use structopt::StructOpt;
use atuin_client::import::{bash::Bash, zsh::Zsh}; use atuin_client::import::{bash::Bash, zsh::Zsh};
use atuin_client::{database::Database, import::Importer}; use atuin_client::{database::Database, import::Importer};
use atuin_client::{history::History, import::resh::Resh}; use atuin_client::{history::History, import::resh::Resh};
use indicatif::ProgressBar; use indicatif::ProgressBar;
#[derive(StructOpt)] #[derive(Parser)]
#[clap(infer_subcommands = true)]
pub enum Cmd { pub enum Cmd {
#[structopt( /// Import history for the current shell
about="import history for the current shell",
aliases=&["a", "au", "aut"],
)]
Auto, Auto,
#[structopt( /// Import history from the zsh history file
about="import history from the zsh history file",
aliases=&["z", "zs"],
)]
Zsh, Zsh,
#[structopt( /// Import history from the bash history file
about="import history from the bash history file",
aliases=&["b", "ba", "bas"],
)]
Bash, Bash,
#[structopt( /// Import history from the resh history file
about="import history from the resh history file",
aliases=&["r", "re", "res"],
)]
Resh, Resh,
#[structopt( /// Import history from the fish history file
about="import history from the fish history file",
aliases=&["f", "fi", "fis"],
)]
Fish, Fish,
} }

View file

@ -1,12 +1,12 @@
use structopt::StructOpt; use clap::Parser;
#[derive(StructOpt)] #[derive(Parser)]
pub enum Cmd { pub enum Cmd {
#[structopt(about = "zsh setup")] /// Zsh setup
Zsh, Zsh,
#[structopt(about = "bash setup")] /// Bash setup
Bash, Bash,
#[structopt(about = "fish setup")] /// Fish setup
Fish, Fish,
} }

View file

@ -2,23 +2,25 @@ use std::borrow::Cow;
use std::io; use std::io;
use atuin_common::api::LoginRequest; use atuin_common::api::LoginRequest;
use clap::AppSettings;
use clap::Parser;
use eyre::Result; use eyre::Result;
use structopt::StructOpt;
use tokio::{fs::File, io::AsyncWriteExt}; use tokio::{fs::File, io::AsyncWriteExt};
use atuin_client::api_client; use atuin_client::api_client;
use atuin_client::settings::Settings; use atuin_client::settings::Settings;
#[derive(StructOpt)] #[derive(Parser)]
#[structopt(setting(structopt::clap::AppSettings::DeriveDisplayOrder))] #[clap(setting(AppSettings::DeriveDisplayOrder))]
pub struct Cmd { pub struct Cmd {
#[structopt(long, short)] #[clap(long, short)]
pub username: Option<String>, pub username: Option<String>,
#[structopt(long, short)] #[clap(long, short)]
pub password: Option<String>, 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>, pub key: Option<String>,
} }

View file

@ -1,8 +1,10 @@
use std::path::PathBuf; 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 eyre::{Result, WrapErr};
use structopt::clap::Shell;
use structopt::StructOpt;
use atuin_client::database::Sqlite; use atuin_client::database::Sqlite;
use atuin_client::settings::Settings as ClientSettings; use atuin_client::settings::Settings as ClientSettings;
@ -21,86 +23,101 @@ mod server;
mod stats; mod stats;
mod sync; mod sync;
#[derive(StructOpt)] #[derive(Subcommand)]
#[clap(infer_subcommands = true)]
pub enum AtuinCmd { pub enum AtuinCmd {
#[structopt( /// Manipulate shell history
about="manipulate shell history", #[clap(subcommand)]
aliases=&["h", "hi", "his", "hist", "histo", "histor"],
)]
History(history::Cmd), History(history::Cmd),
#[structopt(about = "import shell history from file")] /// Import shell history from file
#[clap(subcommand)]
Import(import::Cmd), Import(import::Cmd),
#[structopt(about = "start an atuin server")] /// Start an atuin server
#[clap(subcommand)]
Server(server::Cmd), Server(server::Cmd),
#[structopt(about = "calculate statistics for your history")] /// Calculate statistics for your history
#[clap(subcommand)]
Stats(stats::Cmd), Stats(stats::Cmd),
#[structopt(about = "output shell setup")] /// Output shell setup
#[clap(subcommand)]
Init(init::Cmd), Init(init::Cmd),
#[structopt(about = "generates a UUID")] /// Generate a UUID
Uuid, Uuid,
#[structopt(about = "interactive history search")] /// Interactive history search
Search { Search {
#[structopt(long, short, help = "filter search result by directory")] /// Filter search result by directory
#[clap(long, short)]
cwd: Option<String>, cwd: Option<String>,
#[structopt(long = "exclude-cwd", help = "exclude directory from results")] /// Exclude directory from results
#[clap(long = "exclude-cwd")]
exclude_cwd: Option<String>, 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>, 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>, 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>, before: Option<String>,
#[structopt(long, help = "only include results after this date")] /// Only include results after this date
#[clap(long)]
after: Option<String>, after: Option<String>,
#[structopt(long, short, help = "open interactive search UI")] /// Open interactive search UI
#[clap(long, short)]
interactive: bool, interactive: bool,
#[structopt(long, short, help = "use human-readable formatting for time")] /// Use human-readable formatting for time
#[clap(long)]
human: bool, human: bool,
query: Vec<String>, 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, cmd_only: bool,
}, },
#[structopt(about = "sync with the configured server")] /// Sync with the configured server
Sync { Sync {
#[structopt(long, short, help = "force re-download everything")] /// Force re-download everything
#[clap(long, short)]
force: bool, force: bool,
}, },
#[structopt(about = "login to the configured server")] /// Login to the configured server
Login(login::Cmd), Login(login::Cmd),
#[structopt(about = "log out")] /// Log out
Logout, Logout,
#[structopt(about = "register with the configured server")] /// Register with the configured server
Register(register::Cmd), Register(register::Cmd),
#[structopt(about = "print the encryption key for transfer to another machine")] /// Print the encryption key for transfer to another machine
Key, Key,
#[structopt(about = "generate shell completions")] /// Generate shell completions
GenCompletions { GenCompletions {
#[structopt(long, short, help = "set the shell for generating completions")] /// Set the shell for generating completions
#[clap(long, short)]
shell: Shell, shell: Shell,
#[structopt(long, short, help = "set the output directory")] /// Set the output directory
out_dir: String, #[clap(long, short)]
out_dir: Option<String>,
}, },
} }
@ -172,11 +189,22 @@ impl AtuinCmd {
Ok(()) Ok(())
} }
Self::GenCompletions { shell, out_dir } => { Self::GenCompletions { shell, out_dir } => {
AtuinCmd::clap().gen_completions(env!("CARGO_PKG_NAME"), shell, &out_dir); let mut cli = crate::Atuin::command();
println!(
"Shell completion for {} is generated in {:?}", match out_dir {
shell, 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(()) Ok(())
} }
} }

View file

@ -1,20 +1,21 @@
use clap::AppSettings;
use clap::Parser;
use eyre::Result; use eyre::Result;
use structopt::StructOpt;
use tokio::{fs::File, io::AsyncWriteExt}; use tokio::{fs::File, io::AsyncWriteExt};
use atuin_client::api_client; use atuin_client::api_client;
use atuin_client::settings::Settings; use atuin_client::settings::Settings;
#[derive(StructOpt)] #[derive(Parser)]
#[structopt(setting(structopt::clap::AppSettings::DeriveDisplayOrder))] #[clap(setting(AppSettings::DeriveDisplayOrder))]
pub struct Cmd { pub struct Cmd {
#[structopt(long, short)] #[clap(long, short)]
pub username: Option<String>, pub username: Option<String>,
#[structopt(long, short)] #[clap(long, short)]
pub email: Option<String>, pub email: Option<String>,
#[structopt(long, short)] #[clap(long, short)]
pub password: Option<String>, pub password: Option<String>,
} }

View file

@ -1,20 +1,20 @@
use clap::Parser;
use eyre::Result; use eyre::Result;
use structopt::StructOpt;
use atuin_server::launch; use atuin_server::launch;
use atuin_server::settings::Settings; use atuin_server::settings::Settings;
#[derive(StructOpt)] #[derive(Parser)]
#[clap(infer_subcommands = true)]
pub enum Cmd { pub enum Cmd {
#[structopt( /// Start the server
about="starts the server",
aliases=&["s", "st", "sta", "star"],
)]
Start { Start {
#[structopt(help = "specify the host address to bind", long, short)] /// The host address to bind
#[clap(long, short)]
host: Option<String>, host: Option<String>,
#[structopt(help = "specify the port to bind", long, short)] /// The port to bind
#[clap(long, short)]
port: Option<u16>, port: Option<u16>,
}, },
} }

View file

@ -4,26 +4,21 @@ use chrono::prelude::*;
use chrono::Duration; use chrono::Duration;
use chrono_english::parse_date_string; use chrono_english::parse_date_string;
use clap::Parser;
use cli_table::{format::Justify, print_stdout, Cell, Style, Table}; use cli_table::{format::Justify, print_stdout, Cell, Style, Table};
use eyre::{eyre, Result}; use eyre::{eyre, Result};
use structopt::StructOpt;
use atuin_client::database::Database; use atuin_client::database::Database;
use atuin_client::history::History; use atuin_client::history::History;
use atuin_client::settings::Settings; use atuin_client::settings::Settings;
#[derive(StructOpt)] #[derive(Parser)]
#[clap(infer_subcommands = true)]
pub enum Cmd { pub enum Cmd {
#[structopt( /// Compute statistics for all of time
about="compute statistics for all of time",
aliases=&["d", "da"],
)]
All, All,
#[structopt( /// Compute statistics for a single day
about="compute statistics for a single day",
aliases=&["d", "da"],
)]
Day { words: Vec<String> }, Day { words: Vec<String> },
} }

View file

@ -1,8 +1,9 @@
#![warn(clippy::pedantic, clippy::nursery)] #![warn(clippy::pedantic, clippy::nursery)]
#![allow(clippy::use_self)] // not 100% reliable #![allow(clippy::use_self)] // not 100% reliable
use clap::AppSettings;
use clap::Parser;
use eyre::Result; use eyre::Result;
use structopt::{clap::AppSettings, StructOpt};
#[macro_use] #[macro_use]
extern crate log; extern crate log;
@ -13,15 +14,15 @@ mod command;
const VERSION: &str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(StructOpt)] /// Magical shell history
#[structopt( #[derive(Parser)]
#[clap(
author = "Ellie Huxtable <e@elm.sh>", author = "Ellie Huxtable <e@elm.sh>",
version = VERSION, version = VERSION,
about = "Magical shell history", global_setting(AppSettings::DeriveDisplayOrder),
global_settings(&[AppSettings::ColoredHelp, AppSettings::DeriveDisplayOrder])
)] )]
struct Atuin { struct Atuin {
#[structopt(subcommand)] #[clap(subcommand)]
atuin: AtuinCmd, atuin: AtuinCmd,
} }
@ -35,5 +36,5 @@ impl Atuin {
async fn main() -> Result<()> { async fn main() -> Result<()> {
pretty_env_logger::init(); pretty_env_logger::init();
Atuin::from_args().run().await Atuin::parse().run().await
} }