summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-04-25 16:32:41 +0000
committerLars Wirzenius <liw@liw.fi>2022-04-25 16:32:41 +0000
commit491396ae87d5f0061c7f5da9f404d988f4e16bac (patch)
tree3dd6e59954434782941c5cca4d0562e4041777b6
parent4305a22cd719ec1aaadb46796bbd7fc84f2161f0 (diff)
parent398f412253d9a9c00ba7fc4dfc48591a8c17789b (diff)
downloadjt2-491396ae87d5f0061c7f5da9f404d988f4e16bac.tar.gz
Merge branch 'clap3' into 'main'
chore: port from structopt to clap v3 See merge request larswirzenius/jt!31
-rw-r--r--Cargo.lock111
-rw-r--r--Cargo.toml2
-rw-r--r--src/bin/jt.rs4
-rw-r--r--src/cmd.rs32
-rw-r--r--src/opt.rs14
5 files changed, 68 insertions, 95 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 8217944..adb61ad 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -12,15 +12,6 @@ dependencies = [
]
[[package]]
-name = "ansi_term"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
-dependencies = [
- "winapi",
-]
-
-[[package]]
name = "anyhow"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -112,17 +103,41 @@ dependencies = [
[[package]]
name = "clap"
-version = "2.33.3"
+version = "3.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
+checksum = "7c167e37342afc5f33fd87bbc870cedd020d2a6dffa05d45ccd9241fbdd146db"
dependencies = [
- "ansi_term",
"atty",
"bitflags",
+ "clap_derive",
+ "clap_lex",
+ "indexmap",
+ "lazy_static",
"strsim",
+ "termcolor",
"textwrap",
- "unicode-width",
- "vec_map",
+]
+
+[[package]]
+name = "clap_derive"
+version = "3.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "clap_lex"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "189ddd3b5d32a70b35e7686054371742a937b0d99128e76dde6340210e966669"
+dependencies = [
+ "os_str_bytes",
]
[[package]]
@@ -254,12 +269,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "heck"
-version = "0.3.3"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
-dependencies = [
- "unicode-segmentation",
-]
+checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
@@ -319,6 +331,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"chrono",
+ "clap",
"directories-next",
"glob",
"log",
@@ -326,7 +339,6 @@ dependencies = [
"regex",
"serde",
"serde_yaml",
- "structopt",
"tera",
"thiserror",
]
@@ -402,6 +414,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
+name = "os_str_bytes"
+version = "6.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
+
+[[package]]
name = "pest"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -610,33 +628,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.22"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "69b041cdcb67226aca307e6e7be44c8806423d83e018bd662360a93dabce4d71"
-dependencies = [
- "clap",
- "lazy_static",
- "structopt-derive",
-]
-
-[[package]]
-name = "structopt-derive"
-version = "0.4.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7813934aecf5f51a54775e00068c237de98489463968231a51746bbbc03f9c10"
-dependencies = [
- "heck",
- "proc-macro-error",
- "proc-macro2",
- "quote",
- "syn",
-]
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
@@ -676,12 +670,9 @@ dependencies = [
[[package]]
name = "textwrap"
-version = "0.11.0"
+version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
-dependencies = [
- "unicode-width",
-]
+checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]]
name = "thiserror"
@@ -785,30 +776,12 @@ dependencies = [
]
[[package]]
-name = "unicode-segmentation"
-version = "1.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
-
-[[package]]
-name = "unicode-width"
-version = "0.1.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
-
-[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index c408230..893e00e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
anyhow = "1"
chrono = "0.4"
+clap = { version = "3.1.12", features = ["derive"] }
directories-next = "2.0.0"
glob = "0.3.0"
log = "0.4"
@@ -14,6 +15,5 @@ pretty_env_logger = "0.4"
regex = "1.5.4"
serde = { version = "1", features = ["derive"] }
serde_yaml = "0.8"
-structopt = "0.3"
tera = { version = "1", default-features = false }
thiserror = "1"
diff --git a/src/bin/jt.rs b/src/bin/jt.rs
index 11fc45d..21bf254 100644
--- a/src/bin/jt.rs
+++ b/src/bin/jt.rs
@@ -1,7 +1,7 @@
use jt::config::Configuration;
use jt::opt::{Opt, SubCommand};
-use structopt::StructOpt;
+use clap::Parser;
fn main() {
if let Err(err) = do_work() {
@@ -12,7 +12,7 @@ fn main() {
fn do_work() -> anyhow::Result<()> {
pretty_env_logger::init_custom_env("JT_LOG");
- let opt = Opt::from_args();
+ let opt = Opt::parse();
let config = Configuration::read(&opt)?;
match opt.cmd {
SubCommand::Config(x) => x.run(&config)?,
diff --git a/src/cmd.rs b/src/cmd.rs
index 9cec3b5..07f985f 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -1,11 +1,11 @@
use crate::config::Configuration;
use crate::error::JournalError;
use crate::journal::Journal;
+use clap::Parser;
use log::debug;
use std::path::PathBuf;
-use structopt::StructOpt;
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Config {}
impl Config {
@@ -15,12 +15,12 @@ impl Config {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Init {
- #[structopt(help = "Short name for journal")]
+ #[clap(help = "Short name for journal")]
journalname: String,
- #[structopt(help = "Short description of journal, its title")]
+ #[clap(help = "Short description of journal, its title")]
description: String,
}
@@ -35,7 +35,7 @@ impl Init {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct IsJournal {}
impl IsJournal {
@@ -49,12 +49,12 @@ impl IsJournal {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct New {
- #[structopt(help = "Title of new draft")]
+ #[clap(help = "Title of new draft")]
title: String,
- #[structopt(long, help = "Add link to a topic page")]
+ #[clap(long, help = "Add link to a topic page")]
topic: Option<PathBuf>,
}
@@ -66,7 +66,7 @@ impl New {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct List {}
impl List {
@@ -77,12 +77,12 @@ impl List {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct NewTopic {
- #[structopt(help = "Path to topic page in journal")]
+ #[clap(help = "Path to topic page in journal")]
path: PathBuf,
- #[structopt(help = "Title of topic page")]
+ #[clap(help = "Title of topic page")]
title: String,
}
@@ -94,7 +94,7 @@ impl NewTopic {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Edit {
/// Draft id.
draft: String,
@@ -109,7 +109,7 @@ impl Edit {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Remove {
/// Draft id.
draft: String,
@@ -124,7 +124,7 @@ impl Remove {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Finish {
/// Draft id.
draft: String,
diff --git a/src/opt.rs b/src/opt.rs
index 9170e0f..5a81ab6 100644
--- a/src/opt.rs
+++ b/src/opt.rs
@@ -1,26 +1,26 @@
//! Command line options.
use crate::cmd;
+use clap::Parser;
use std::path::PathBuf;
-use structopt::StructOpt;
/// A parsed command line.
-#[derive(Debug, StructOpt)]
-#[structopt(about = "maintain a journal")]
+#[derive(Debug, Parser)]
+#[clap(about = "maintain a journal")]
pub struct Opt {
/// Global options, common for all subcommands.
- #[structopt(flatten)]
+ #[clap(flatten)]
pub global: GlobalOptions,
/// The subcommand.
- #[structopt(subcommand)]
+ #[clap(subcommand)]
pub cmd: SubCommand,
}
/// Global options.
///
/// These options are common to all subcommands.
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct GlobalOptions {
/// Which configuration file to read.
#[structopt(short, long, help = "Configuration file")]
@@ -44,7 +44,7 @@ pub struct GlobalOptions {
}
/// A subcommand.
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub enum SubCommand {
/// Show configuration.
Config(cmd::Config),