clap3.0.0-rc.3

This commit is contained in:
Conrad Ludgate 2021-12-10 17:15:51 +00:00
parent 88b2651ba4
commit dffc5ba9e8
11 changed files with 177 additions and 158 deletions

100
Cargo.lock generated
View File

@ -22,15 +22,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "arrayvec"
version = "0.5.2"
@ -79,6 +70,8 @@ dependencies = [
"base64",
"chrono",
"chrono-english",
"clap",
"clap_generate",
"cli-table",
"crossbeam-channel",
"directories",
@ -92,7 +85,6 @@ dependencies = [
"serde 1.0.132",
"serde_derive",
"serde_json",
"structopt",
"tabwriter",
"termion",
"tokio",
@ -295,17 +287,41 @@ dependencies = [
[[package]]
name = "clap"
version = "2.34.0"
version = "3.0.0-rc.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
checksum = "9468f8012246b0836c6fd11725102b0844254985f2462b6c637d50040ef49df0"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"clap_derive",
"indexmap",
"lazy_static",
"os_str_bytes",
"strsim",
"termcolor",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "clap_derive"
version = "3.0.0-rc.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b72e1af32a4de4d21a43d26de33fe69c00e895371bd8b1523d674f011b610467"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_generate"
version = "3.0.0-rc.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f2270bcbc20764b00bd2aec68661a97814999f88a845ffae8f43d817eea7be0"
dependencies = [
"clap",
]
[[package]]
@ -1285,6 +1301,15 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "os_str_bytes"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
dependencies = [
"memchr",
]
[[package]]
name = "parking_lot"
version = "0.11.2"
@ -1407,9 +1432,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.34"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1"
checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a"
dependencies = [
"unicode-xid",
]
@ -2042,33 +2067,9 @@ dependencies = [
[[package]]
name = "strsim"
version = "0.8.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "structopt"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c"
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",
]
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "subtle"
@ -2143,12 +2144,9 @@ dependencies = [
[[package]]
name = "textwrap"
version = "0.11.0"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
[[package]]
name = "thiserror"
@ -2467,12 +2465,6 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.3"

View File

@ -37,7 +37,8 @@ log = "0.4"
pretty_env_logger = "0.4"
chrono = { version = "0.4", features = ["serde"] }
eyre = "0.6"
structopt = "0.3"
clap = { version = "3.0.0-rc.7", features = ["derive"] }
clap_generate = "3.0.0-rc.7"
directories = "3"
indicatif = "0.16.2"
serde_derive = "1.0.125"

View File

@ -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,46 @@ use atuin_client::history::History;
use atuin_client::settings::Settings;
use atuin_client::sync;
#[derive(StructOpt)]
#[derive(Subcommand)]
#[clap(aliases = &["h", "hi", "his", "hist", "histo", "histor"])]
pub enum Cmd {
#[structopt(
about="begins a new command in the history",
aliases=&["s", "st", "sta", "star"],
)]
/// "begins a new command in the history
#[clap(aliases=&["s", "st", "sta", "star"])]
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)
#[clap(aliases=&["e", "en"])]
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
#[clap(aliases=&["l", "li", "lis"])]
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
#[clap(aliases=&["la", "las"])]
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,
},
}

View File

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

View File

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

View File

@ -2,23 +2,24 @@ use std::borrow::Cow;
use std::io;
use atuin_common::api::LoginRequest;
use clap::{AppSettings, 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>,
}

View File

@ -1,13 +1,13 @@
use std::path::PathBuf;
use clap::{IntoApp, Subcommand};
use eyre::{Result, WrapErr};
use structopt::clap::Shell;
use structopt::StructOpt;
use atuin_client::database::Sqlite;
use atuin_client::settings::Settings as ClientSettings;
use atuin_common::utils::uuid_v4;
use atuin_server::settings::Settings as ServerSettings;
use clap_generate::{generate, generate_to, Generator, Shell};
mod event;
mod history;
@ -21,86 +21,100 @@ mod server;
mod stats;
mod sync;
#[derive(StructOpt)]
#[derive(Subcommand)]
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")]
/// generates 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 +186,26 @@ 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::into_app();
match out_dir {
Some(out_dir) => {
generate_to(shell, &mut cli, env!("CARGO_PKG_NAME"), &out_dir)?;
println!(
"Shell completion for {} is generated in {:?}",
shell, out_dir
);
}
None => {
generate(
shell,
&mut cli,
env!("CARGO_PKG_NAME"),
&mut std::io::stdout(),
);
}
}
Ok(())
}
}

View File

@ -1,20 +1,20 @@
use clap::{AppSettings, 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>,
}

View File

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

View File

@ -4,23 +4,23 @@ use chrono::prelude::*;
use chrono::Duration;
use chrono_english::parse_date_string;
use clap::Subcommand;
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(Subcommand)]
pub enum Cmd {
#[structopt(
#[clap(
about="compute statistics for all of time",
aliases=&["d", "da"],
)]
All,
#[structopt(
#[clap(
about="compute statistics for a single day",
aliases=&["d", "da"],
)]

View File

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