Switch from structopt to clap

This commit is contained in:
Joscha 2022-05-19 13:56:09 +02:00
parent a63529b972
commit bc0d2481c8
3 changed files with 86 additions and 86 deletions

125
Cargo.lock generated
View file

@ -2,15 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[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 = "atty" name = "atty"
version = "0.2.14" version = "0.2.14"
@ -100,17 +91,41 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.34.0" version = "3.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b"
dependencies = [ dependencies = [
"ansi_term",
"atty", "atty",
"bitflags", "bitflags",
"clap_derive",
"clap_lex",
"indexmap",
"lazy_static",
"strsim", "strsim",
"termcolor",
"textwrap", "textwrap",
"unicode-width", ]
"vec_map",
[[package]]
name = "clap_derive"
version = "3.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213"
dependencies = [
"os_str_bytes",
] ]
[[package]] [[package]]
@ -242,13 +257,16 @@ dependencies = [
] ]
[[package]] [[package]]
name = "heck" name = "hashbrown"
version = "0.3.3" version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"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"
@ -259,6 +277,16 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "indexmap"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.12" version = "0.1.12"
@ -338,6 +366,12 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "os_str_bytes"
version = "6.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435"
[[package]] [[package]]
name = "pest" name = "pest"
version = "2.1.3" version = "2.1.3"
@ -500,33 +534,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 = "syn" name = "syn"
@ -564,27 +574,24 @@ 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"
version = "1.0.30" version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.30" version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -607,6 +614,7 @@ name = "today"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap",
"codespan-reporting", "codespan-reporting",
"colored", "colored",
"computus", "computus",
@ -615,7 +623,6 @@ dependencies = [
"pest", "pest",
"pest_derive", "pest_derive",
"promptly", "promptly",
"structopt",
"termcolor", "termcolor",
"thiserror", "thiserror",
"tzfile", "tzfile",
@ -666,12 +673,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372" checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
[[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

@ -5,6 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
chrono = "0.4.19" chrono = "0.4.19"
clap = { version = "3.1.18", features = ["derive"] }
codespan-reporting = "0.11.1" codespan-reporting = "0.11.1"
colored = "2.0.0" colored = "2.0.0"
computus = "1.0.0" computus = "1.0.0"
@ -13,7 +14,6 @@ edit = "0.1.3"
pest = "2.1.3" pest = "2.1.3"
pest_derive = "2.1.0" pest_derive = "2.1.0"
promptly = "0.3.0" promptly = "0.3.0"
structopt = "0.3.26"
termcolor = "1.1.3" termcolor = "1.1.3"
thiserror = "1.0.30" thiserror = "1.0.30"
tzfile = { git = "https://github.com/Garmelon/tzfile.git", branch = "tzdir" } tzfile = { git = "https://github.com/Garmelon/tzfile.git", branch = "tzdir" }

View file

@ -3,9 +3,9 @@ use std::str::FromStr;
use std::{process, result}; use std::{process, result};
use chrono::{NaiveDate, NaiveDateTime}; use chrono::{NaiveDate, NaiveDateTime};
use clap::Parser;
use codespan_reporting::files::SimpleFile; use codespan_reporting::files::SimpleFile;
use directories::ProjectDirs; use directories::ProjectDirs;
use structopt::StructOpt;
use crate::eval::{self, DateRange, Entry, EntryMode}; use crate::eval::{self, DateRange, Entry, EntryMode};
use crate::files::cli::{CliDate, CliIdent, CliRange}; use crate::files::cli::{CliDate, CliIdent, CliRange};
@ -24,77 +24,76 @@ mod print;
mod show; mod show;
mod util; mod util;
#[derive(Debug, StructOpt)] #[derive(Debug, clap::Parser)]
pub struct Opt { pub struct Opt {
/// File to load /// File to load
#[structopt(short, long, parse(from_os_str))] #[clap(short, long)]
file: Option<PathBuf>, file: Option<PathBuf>,
/// Overwrite the current date /// Overwrite the current date
#[structopt(short, long, default_value = "t")] #[clap(short, long, default_value = "t")]
date: String, date: String,
/// Range of days to focus on /// Range of days to focus on
#[structopt(short, long, default_value = "t-2d--t+2w")] #[clap(short, long, default_value = "t-2d--t+2w")]
range: String, range: String,
#[structopt(subcommand)] #[clap(subcommand)]
command: Option<Command>, command: Option<Command>,
} }
#[derive(Debug, StructOpt)] #[derive(Debug, clap::Subcommand)]
pub enum Command { pub enum Command {
/// Shows individual entries in detail /// Shows individual entries in detail
#[structopt(alias = "s")] #[clap(alias = "s")]
Show { Show {
/// Entries and days to show /// Entries and days to show
#[structopt(required = true)] #[clap(required = true)]
identifiers: Vec<String>, identifiers: Vec<String>,
}, },
/// Create a new entry based on a template /// Create a new entry based on a template
#[structopt(alias = "n")] #[clap(alias = "n")]
New { New {
#[structopt(subcommand)] #[clap(subcommand)]
template: Template, template: Template,
}, },
/// Marks one or more entries as done /// Marks one or more entries as done
#[structopt(alias = "d")] #[clap(alias = "d")]
Done { Done {
/// Entries to mark as done /// Entries to mark as done
#[structopt(required = true)] #[clap(required = true)]
entries: Vec<usize>, entries: Vec<usize>,
}, },
/// Marks one or more entries as canceled /// Marks one or more entries as canceled
#[structopt(alias = "c")] #[clap(alias = "c")]
Cancel { Cancel {
/// Entries to mark as done /// Entries to mark as done
#[structopt(required = true)] #[clap(required = true)]
entries: Vec<usize>, entries: Vec<usize>,
}, },
/// Edits or creates a log entry /// Edits or creates a log entry
#[structopt(alias = "l")] #[clap(alias = "l")]
Log { Log {
#[structopt(default_value = "t")] #[clap(default_value = "t")]
date: String, date: String,
}, },
/// Reformats all loaded files /// Reformats all loaded files
Fmt, Fmt,
} }
// TODO Add templates for tasks and notes #[derive(Debug, clap::Subcommand)]
#[derive(Debug, StructOpt)]
pub enum Template { pub enum Template {
/// Adds a task /// Adds a task
#[structopt(alias = "t")] #[clap(alias = "t")]
Task { Task {
/// If specified, the task is dated to this date /// If specified, the task is dated to this date
date: Option<String>, date: Option<String>,
}, },
/// Adds a note /// Adds a note
#[structopt(alias = "n")] #[clap(alias = "n")]
Note { Note {
/// If specified, the note is dated to this date /// If specified, the note is dated to this date
date: Option<String>, date: Option<String>,
}, },
/// Adds an undated task marked as done today /// Adds an undated task marked as done today
#[structopt(alias = "d")] #[clap(alias = "d")]
Done, Done,
} }
@ -222,7 +221,7 @@ fn run_with_files(opt: Opt, files: &mut Files) -> Result<()> {
} }
pub fn run() { pub fn run() {
let opt = Opt::from_args(); let opt = Opt::parse();
let mut files = Files::new(); let mut files = Files::new();
if let Err(e) = load_files(&opt, &mut files) { if let Err(e) = load_files(&opt, &mut files) {