From 5e2c438dabc74d7e87fad46c725501753a0a8a26 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Tue, 18 Oct 2022 09:50:22 +0100 Subject: [PATCH] Upgrade clap (#568) --- Cargo.lock | 24 ++++++++---------------- Cargo.toml | 4 ++-- src/command/client.rs | 8 ++++---- src/command/client/history.rs | 16 ++++++++-------- src/command/client/import.rs | 2 +- src/command/client/search.rs | 20 ++++++++++---------- src/command/client/stats.rs | 2 +- src/command/client/sync.rs | 4 ++-- src/command/client/sync/login.rs | 3 +-- src/command/client/sync/register.rs | 3 +-- src/command/mod.rs | 12 ++++++------ src/main.rs | 18 ++++++++++++++---- 12 files changed, 58 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b70f0e..b9eb0d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -331,35 +331,33 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.21" +version = "4.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ed5341b2301a26ab80be5cbdced622e80ed808483c52e45e3310a877d3b37d7" +checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f" dependencies = [ "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_complete" -version = "3.2.5" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8" +checksum = "11cba7abac9b56dfe2f035098cdb3a43946f276e6db83b72c4e692343f9aab9a" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad" dependencies = [ "heck", "proc-macro-error", @@ -370,9 +368,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -1953,12 +1951,6 @@ dependencies = [ "redox_termios", ] -[[package]] -name = "textwrap" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" - [[package]] name = "thiserror" version = "1.0.34" diff --git a/Cargo.toml b/Cargo.toml index e239740..28c52c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,8 +66,8 @@ chrono-english = "0.1.4" cli-table = { version = "0.4", default-features = false } base64 = "0.13.0" crossbeam-channel = "0.5.1" -clap = { version = "3.1.18", features = ["derive"] } -clap_complete = "3.1.4" +clap = { version = "4.0.14", features = ["derive"] } +clap_complete = "4.0.2" fs-err = "2.7" whoami = "1.1.2" rpassword = "7.0" diff --git a/src/command/client.rs b/src/command/client.rs index 94148c0..f7b9d6f 100644 --- a/src/command/client.rs +++ b/src/command/client.rs @@ -14,14 +14,14 @@ mod search; mod stats; #[derive(Subcommand)] -#[clap(infer_subcommands = true)] +#[command(infer_subcommands = true)] pub enum Cmd { /// Manipulate shell history - #[clap(subcommand)] + #[command(subcommand)] History(history::Cmd), /// Import shell history from file - #[clap(subcommand)] + #[command(subcommand)] Import(import::Cmd), /// Calculate statistics for your history @@ -31,7 +31,7 @@ pub enum Cmd { Search(search::Cmd), #[cfg(feature = "sync")] - #[clap(flatten)] + #[command(flatten)] Sync(sync::Cmd), } diff --git a/src/command/client/history.rs b/src/command/client/history.rs index 07f4b31..6a78adc 100644 --- a/src/command/client/history.rs +++ b/src/command/client/history.rs @@ -20,7 +20,7 @@ use log::debug; use super::search::format_duration; #[derive(Subcommand)] -#[clap(infer_subcommands = true)] +#[command(infer_subcommands = true)] pub enum Cmd { /// Begins a new command in the history Start { command: Vec }, @@ -28,33 +28,33 @@ pub enum Cmd { /// Finishes a new command in the history (adds time, exit code) End { id: String, - #[clap(long, short)] + #[arg(long, short)] exit: i64, }, /// List all items in history List { - #[clap(long, short)] + #[arg(long, short)] cwd: bool, - #[clap(long, short)] + #[arg(long, short)] session: bool, - #[clap(long)] + #[arg(long)] human: bool, /// Show only the text of the command - #[clap(long)] + #[arg(long)] cmd_only: bool, }, /// Get the last command ran Last { - #[clap(long)] + #[arg(long)] human: bool, /// Show only the text of the command - #[clap(long)] + #[arg(long)] cmd_only: bool, }, } diff --git a/src/command/client/import.rs b/src/command/client/import.rs index 60fd536..b0375ac 100644 --- a/src/command/client/import.rs +++ b/src/command/client/import.rs @@ -14,7 +14,7 @@ use atuin_client::{ }; #[derive(Parser)] -#[clap(infer_subcommands = true)] +#[command(infer_subcommands = true)] pub enum Cmd { /// Import history for the current shell Auto, diff --git a/src/command/client/search.rs b/src/command/client/search.rs index 1cef1ff..26026f3 100644 --- a/src/command/client/search.rs +++ b/src/command/client/search.rs @@ -18,45 +18,45 @@ pub use duration::format_duration; #[derive(Parser)] pub struct Cmd { /// Filter search result by directory - #[clap(long, short)] + #[arg(long, short)] cwd: Option, /// Exclude directory from results - #[clap(long = "exclude-cwd")] + #[arg(long = "exclude-cwd")] exclude_cwd: Option, /// Filter search result by exit code - #[clap(long, short)] + #[arg(long, short)] exit: Option, /// Exclude results with this exit code - #[clap(long = "exclude-exit")] + #[arg(long = "exclude-exit")] exclude_exit: Option, /// Only include results added before this date - #[clap(long, short)] + #[arg(long, short)] before: Option, /// Only include results after this date - #[clap(long)] + #[arg(long)] after: Option, /// How many entries to return at most - #[clap(long)] + #[arg(long)] limit: Option, /// Open interactive search UI - #[clap(long, short)] + #[arg(long, short)] interactive: bool, /// Use human-readable formatting for time - #[clap(long)] + #[arg(long)] human: bool, query: Vec, /// Show only the text of the command - #[clap(long)] + #[arg(long)] cmd_only: bool, } diff --git a/src/command/client/stats.rs b/src/command/client/stats.rs index 157496d..a00eb36 100644 --- a/src/command/client/stats.rs +++ b/src/command/client/stats.rs @@ -13,7 +13,7 @@ use atuin_client::{ }; #[derive(Parser)] -#[clap(infer_subcommands = true)] +#[command(infer_subcommands = true)] pub struct Cmd { /// compute statistics for the specified period, leave blank for statistics since the beginning period: Vec, diff --git a/src/command/client/sync.rs b/src/command/client/sync.rs index af809f3..51fcbf6 100644 --- a/src/command/client/sync.rs +++ b/src/command/client/sync.rs @@ -8,12 +8,12 @@ mod logout; mod register; #[derive(Subcommand)] -#[clap(infer_subcommands = true)] +#[command(infer_subcommands = true)] pub enum Cmd { /// Sync with the configured server Sync { /// Force re-download everything - #[clap(long, short)] + #[arg(long, short)] force: bool, }, diff --git a/src/command/client/sync/login.rs b/src/command/client/sync/login.rs index 2922256..333a151 100644 --- a/src/command/client/sync/login.rs +++ b/src/command/client/sync/login.rs @@ -1,6 +1,6 @@ use std::io; -use clap::{AppSettings, Parser}; +use clap::Parser; use eyre::Result; use tokio::{fs::File, io::AsyncWriteExt}; @@ -9,7 +9,6 @@ use atuin_common::api::LoginRequest; use rpassword::prompt_password; #[derive(Parser)] -#[clap(setting(AppSettings::DeriveDisplayOrder))] pub struct Cmd { #[clap(long, short)] pub username: Option, diff --git a/src/command/client/sync/register.rs b/src/command/client/sync/register.rs index 2b5b9ce..6b51fac 100644 --- a/src/command/client/sync/register.rs +++ b/src/command/client/sync/register.rs @@ -1,11 +1,10 @@ -use clap::{AppSettings, Parser}; +use clap::Parser; use eyre::Result; use tokio::{fs::File, io::AsyncWriteExt}; use atuin_client::{api_client, settings::Settings}; #[derive(Parser)] -#[clap(setting(AppSettings::DeriveDisplayOrder))] pub struct Cmd { #[clap(long, short)] pub username: Option, diff --git a/src/command/mod.rs b/src/command/mod.rs index df6b66e..038b24c 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -13,19 +13,19 @@ mod init; mod contributors; #[derive(Subcommand)] -#[clap(infer_subcommands = true)] +#[command(infer_subcommands = true)] pub enum AtuinCmd { #[cfg(feature = "client")] - #[clap(flatten)] + #[command(flatten)] Client(client::Cmd), /// Start an atuin server #[cfg(feature = "server")] - #[clap(subcommand)] + #[command(subcommand)] Server(server::Cmd), /// Output shell setup - #[clap(subcommand)] + #[command(subcommand)] Init(init::Cmd), /// Generate a UUID @@ -36,11 +36,11 @@ pub enum AtuinCmd { /// Generate shell completions GenCompletions { /// Set the shell for generating completions - #[clap(long, short)] + #[arg(long, short)] shell: Shell, /// Set the output directory - #[clap(long, short)] + #[arg(long, short)] out_dir: Option, }, } diff --git a/src/main.rs b/src/main.rs index 798f7a2..2f81f4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #![warn(clippy::pedantic, clippy::nursery)] #![allow(clippy::use_self, clippy::missing_const_for_fn)] // not 100% reliable -use clap::{AppSettings, Parser}; +use clap::Parser; use eyre::Result; use command::AtuinCmd; @@ -9,15 +9,25 @@ mod command; const VERSION: &str = env!("CARGO_PKG_VERSION"); +static HELP_TEMPLATE: &str = "\ +{before-help}{name} {version} +{author} +{about} + +{usage-heading} + {usage} + +{all-args}{after-help}"; + /// Magical shell history #[derive(Parser)] -#[clap( +#[command( author = "Ellie Huxtable ", version = VERSION, - global_setting(AppSettings::DeriveDisplayOrder), + help_template(HELP_TEMPLATE), )] struct Atuin { - #[clap(subcommand)] + #[command(subcommand)] atuin: AtuinCmd, }