diff --git a/b/Cargo.lock b/b/Cargo.lock index dd1f6a56..91971ab4 100644 --- a/b/Cargo.lock +++ b/b/Cargo.lock @@ -34,15 +34,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" version = "1.0.69" @@ -69,17 +60,6 @@ dependencies = [ "wait-timeout", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -93,13 +73,14 @@ dependencies = [ "adapter_fs", "anyhow", "assert_cmd", + "clap", + "clap_complete", "entity", "limited-date-time", "nom 6.2.1", "predicates 1.0.8", "serde", "serde_json", - "structopt", "tempfile", "thiserror", "use_case", @@ -170,17 +151,48 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "4.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" dependencies = [ - "ansi_term", - "atty", "bitflags", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", "strsim", - "textwrap", - "unicode-width", - "vec_map", + "termcolor", +] + +[[package]] +name = "clap_complete" +version = "4.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501ff0a401473ea1d4c3b125ff95506b62c5bc5768d818634195fbb7c4ad5ff4" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -354,21 +366,15 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.3" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] name = "iana-time-zone" @@ -413,6 +419,18 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "is-terminal" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -561,6 +579,12 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + [[package]] name = "predicates" version = "1.0.8" @@ -767,33 +791,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[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.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", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -840,15 +840,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95059e91184749cb66be6dc994f67f182b6d897cb3df74a5bf66b5e709295fd8" -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.39" @@ -886,12 +877,6 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-width" version = "0.1.10" @@ -907,12 +892,6 @@ dependencies = [ "nom 7.1.3", ] -[[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.4" diff --git a/b/crates/application/Cargo.toml b/b/crates/application/Cargo.toml index 036b2de5..87d02a6a 100644 --- a/b/crates/application/Cargo.toml +++ b/b/crates/application/Cargo.toml @@ -9,12 +9,13 @@ edition = "2018" [dependencies] adapter_fs = { path = "../adapter_fs" } anyhow = "1.0.41" +clap = { version = "4.1.8", features = ["derive"] } +clap_complete = "4.1.4" entity = { path = "../entity" } limited-date-time = { git = "https://github.com/bouzuya/rust-limited-date-time", tag = "0.15.0" } nom = "6.1.2" serde = { version = "1.0.126", features = ["derive"] } serde_json = "1.0.64" -structopt = "0.3.21" thiserror = "1.0.24" use_case = { path = "../use_case" } xdg = "2.4.0" diff --git a/b/crates/application/src/main.rs b/b/crates/application/src/main.rs index b2b55499..ed9c253f 100644 --- a/b/crates/application/src/main.rs +++ b/b/crates/application/src/main.rs @@ -2,46 +2,44 @@ mod command; mod config; use adapter_fs::FsBRepository; +use clap_complete::{generate, Shell}; use config::{Config, ConfigRepository}; use entity::BId; use limited_date_time::TimeZoneOffset; use std::{io, path::PathBuf, str::FromStr}; -use structopt::{clap::Shell, StructOpt}; use use_case::{HasBRepository, HasListUseCase, HasViewUseCase}; -#[derive(Debug, StructOpt)] +#[derive(Debug, clap::Parser)] struct Opt { - #[structopt(subcommand)] + #[command(subcommand)] subcommand: Subcommand, } -#[derive(Debug, StructOpt)] +#[derive(Debug, clap::Subcommand)] enum Subcommand { - #[structopt(name = "completion", about = "Prints the shell's completion script")] + /// Prints the shell's completion script Completion { - #[structopt(name = "SHELL", help = "the shell", possible_values = &Shell::variants())] + #[arg(name = "SHELL", help = "the shell", value_enum)] shell: Shell, }, - #[structopt(name = "list", about = "Lists b files")] + /// Lists b files List { - #[structopt(long = "json")] + #[arg(long)] json: bool, query: String, }, - #[structopt(name = "new", about = "Creates a new file")] + /// Creates a new file New { - #[structopt(short = "d", long = "data-file", help = "The data file")] + /// The data file + #[arg(short, long)] data_file: PathBuf, - #[structopt( - short = "t", - long = "template", - help = "The template file or directory" - )] + /// The template file or directory + #[arg(short, long)] template: PathBuf, }, - #[structopt(name = "view", about = "Views the b file")] + /// Views the b file View { - #[structopt(name = "BID")] + #[arg(name = "BID")] id: BId, }, } @@ -84,10 +82,11 @@ fn build_app(config: Config) -> anyhow::Result { } fn main() -> anyhow::Result<()> { - let opt = Opt::from_args(); + let opt = ::parse(); match opt.subcommand { Subcommand::Completion { shell } => { - Opt::clap().gen_completions_to("b", shell, &mut io::stdout()); + let mut command = ::command(); + generate(shell, &mut command, "b", &mut io::stdout()); Ok(()) } Subcommand::List { json, query } => {