Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade clap #568

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/command/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +31,7 @@ pub enum Cmd {
Search(search::Cmd),

#[cfg(feature = "sync")]
#[clap(flatten)]
#[command(flatten)]
Sync(sync::Cmd),
}

Expand Down
16 changes: 8 additions & 8 deletions src/command/client/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,41 @@ 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<String> },

/// 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,
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/command/client/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions src/command/client/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// Exclude directory from results
#[clap(long = "exclude-cwd")]
#[arg(long = "exclude-cwd")]
exclude_cwd: Option<String>,

/// Filter search result by exit code
#[clap(long, short)]
#[arg(long, short)]
exit: Option<i64>,

/// Exclude results with this exit code
#[clap(long = "exclude-exit")]
#[arg(long = "exclude-exit")]
exclude_exit: Option<i64>,

/// Only include results added before this date
#[clap(long, short)]
#[arg(long, short)]
before: Option<String>,

/// Only include results after this date
#[clap(long)]
#[arg(long)]
after: Option<String>,

/// How many entries to return at most
#[clap(long)]
#[arg(long)]
limit: Option<i64>,

/// 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<String>,

/// Show only the text of the command
#[clap(long)]
#[arg(long)]
cmd_only: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion src/command/client/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/command/client/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},

Expand Down
3 changes: 1 addition & 2 deletions src/command/client/sync/login.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use clap::{AppSettings, Parser};
use clap::Parser;
use eyre::Result;
use tokio::{fs::File, io::AsyncWriteExt};

Expand All @@ -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<String>,
Expand Down
3 changes: 1 addition & 2 deletions src/command/client/sync/register.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
Expand Down
12 changes: 6 additions & 6 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String>,
},
}
Expand Down
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
#![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;
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 <e@elm.sh>",
version = VERSION,
global_setting(AppSettings::DeriveDisplayOrder),
help_template(HELP_TEMPLATE),
)]
struct Atuin {
#[clap(subcommand)]
#[command(subcommand)]
atuin: AtuinCmd,
}

Expand Down