summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock71
-rw-r--r--Cargo.toml2
-rw-r--r--src/bin/subplot.rs70
-rw-r--r--src/diagrams.rs13
-rw-r--r--src/resource.rs6
5 files changed, 112 insertions, 50 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 778bbfe..aef690f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -118,13 +118,52 @@ dependencies = [
"ansi_term",
"atty",
"bitflags",
- "strsim",
+ "strsim 0.8.0",
"textwrap 0.11.0",
"unicode-width",
"vec_map",
]
[[package]]
+name = "clap"
+version = "3.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b"
+dependencies = [
+ "atty",
+ "bitflags",
+ "clap_derive",
+ "clap_lex",
+ "indexmap",
+ "lazy_static",
+ "strsim 0.10.0",
+ "termcolor",
+ "textwrap 0.15.0",
+]
+
+[[package]]
+name = "clap_derive"
+version = "3.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c"
+dependencies = [
+ "heck 0.4.0",
+ "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]]
name = "crossbeam-channel"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -396,6 +435,12 @@ dependencies = [
]
[[package]]
+name = "heck"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
+
+[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -587,6 +632,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 = "pandoc"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1033,12 +1084,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
+name = "strsim"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
+[[package]]
name = "structopt"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
dependencies = [
- "clap",
+ "clap 2.34.0",
"lazy_static",
"structopt-derive",
]
@@ -1049,7 +1106,7 @@ version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [
- "heck",
+ "heck 0.3.3",
"proc-macro-error",
"proc-macro2",
"quote",
@@ -1062,6 +1119,7 @@ version = "0.4.0"
dependencies = [
"anyhow",
"base64",
+ "clap 3.1.18",
"env_logger 0.9.0",
"file_diff",
"git-testament",
@@ -1079,7 +1137,6 @@ dependencies = [
"serde-aux",
"serde_json",
"serde_yaml",
- "structopt",
"tempfile",
"tempfile-fast",
"tera",
@@ -1224,6 +1281,12 @@ dependencies = [
]
[[package]]
+name = "textwrap"
+version = "0.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
+
+[[package]]
name = "thiserror"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 523794a..7e07c83 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -25,6 +25,7 @@ ast_08 = ["pandoc_ast_08"]
[dependencies]
anyhow = "1"
base64 = "0.13.0"
+clap = { version = "3", features = ["derive", "env"] }
file_diff = "1"
git-testament = "0.2"
lazy_static = "1"
@@ -41,7 +42,6 @@ serde = { version = "1.0.101", features = ["derive"] }
serde-aux = { version = "3.0", default-features = false }
serde_json = "1.0"
serde_yaml = "0.8.11"
-structopt = "0.3"
tempfile = "3.1.0"
tempfile-fast = "0.3.1"
thiserror = "1"
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs
index 479aa79..f693a24 100644
--- a/src/bin/subplot.rs
+++ b/src/bin/subplot.rs
@@ -5,12 +5,12 @@ use anyhow::Result;
use env_logger::fmt::Color;
use log::{debug, error, info, trace, warn};
-use structopt::StructOpt;
use subplot::{
codegen, load_document, resource, DataFile, Document, MarkupOpts, Style, SubplotError,
};
use time::{format_description::FormatItem, macros::format_description, OffsetDateTime};
+use clap::{CommandFactory, FromArgMatches, Parser};
use std::convert::TryFrom;
use std::ffi::OsString;
use std::fs::{self, write, File};
@@ -25,15 +25,15 @@ use git_testament::*;
git_testament!(VERSION);
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
struct Toplevel {
- #[structopt(flatten)]
+ #[clap(flatten)]
resources: resource::ResourceOpts,
- #[structopt(flatten)]
+ #[clap(flatten)]
markup: MarkupOpts,
- #[structopt(flatten)]
+ #[clap(subcommand)]
command: Cmd,
}
@@ -50,13 +50,14 @@ impl Toplevel {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
enum Cmd {
Extract(Extract),
Filter(Filter),
Metadata(Metadata),
Docgen(Docgen),
Codegen(Codegen),
+ #[clap(hide = true)]
Resources(Resources),
}
@@ -111,9 +112,8 @@ fn long_version() -> Result<String> {
Ok(ret)
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
/// Examine embedded resources built into Subplot
-#[structopt(setting = structopt::clap::AppSettings::Hidden)]
struct Resources {}
impl Resources {
@@ -127,7 +127,7 @@ impl Resources {
Ok(())
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
/// Extract embedded files from a subplot document
///
/// If no embedded filenames are provided, this will
@@ -135,25 +135,25 @@ impl Resources {
/// is not specified then this will extract to the current directory.
struct Extract {
/// Allow warnings in document?
- #[structopt(long)]
+ #[clap(long)]
merciful: bool,
/// Directory to write extracted files to
- #[structopt(
+ #[clap(
name = "DIR",
long = "directory",
- short = "d",
+ short = 'd',
parse(from_os_str),
default_value = "."
)]
directory: PathBuf,
/// Don't actually write the files out
- #[structopt(long)]
+ #[clap(long)]
dry_run: bool,
/// Input subplot document filename
- #[structopt(parse(from_os_str))]
+ #[clap(parse(from_os_str))]
filename: PathBuf,
/// Names of embedded files to be extracted.
@@ -193,7 +193,7 @@ impl Extract {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
/// Filter a pandoc JSON document.
///
/// This filters a pandoc JSON document, applying Subplot's formatting rules and
@@ -201,15 +201,15 @@ impl Extract {
///
/// If input/output filename is provided, this operates on STDIN/STDOUT.
struct Filter {
- #[structopt(name = "INPUT", long = "input", short = "i", parse(from_os_str))]
+ #[clap(name = "INPUT", long = "input", short = 'i', parse(from_os_str))]
/// Input file (uses STDIN if omitted)
input: Option<PathBuf>,
- #[structopt(name = "OUTPUT", long = "output", short = "o", parse(from_os_str))]
+ #[clap(name = "OUTPUT", long = "output", short = 'o', parse(from_os_str))]
/// Output file (uses STDOUT if omitted)
output: Option<PathBuf>,
- #[structopt(name = "BASE", long = "base", short = "b", parse(from_os_str))]
+ #[clap(name = "BASE", long = "base", short = 'b', parse(from_os_str))]
/// Base directory (defaults to dir of input if given, or '.' if using STDIN)
base: Option<PathBuf>,
}
@@ -246,7 +246,7 @@ impl Filter {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
/// Extract metadata about a document
///
/// Load and process a subplot document, extracting various metadata about the
@@ -254,15 +254,15 @@ impl Filter {
/// or as a JSON object for further scripted processing.
struct Metadata {
/// Allow warnings in document?
- #[structopt(long)]
+ #[clap(long)]
merciful: bool,
/// Form that you want the output to take
- #[structopt(short = "o", default_value = "plain", possible_values=&["plain", "json"])]
+ #[clap(short = 'o', default_value = "plain", possible_values=&["plain", "json"])]
output_format: cli::OutputFormat,
/// Input subplot document filename
- #[structopt(parse(from_os_str))]
+ #[clap(parse(from_os_str))]
filename: PathBuf,
}
@@ -282,31 +282,31 @@ impl Metadata {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
/// Typeset subplot document
///
/// Process a subplot document and typeset it using Pandoc.
struct Docgen {
/// Allow warnings in document?
- #[structopt(long)]
+ #[clap(long)]
merciful: bool,
/// The template to use from the document.
///
/// If not specified, subplot will try and find a unique template name from the document
- #[structopt(name = "TEMPLATE", long = "--template", short = "-t")]
+ #[clap(name = "TEMPLATE", long = "template", short = 't')]
template: Option<String>,
// Input Subplot document
- #[structopt(parse(from_os_str))]
+ #[clap(parse(from_os_str))]
input: PathBuf,
// Output document filename
- #[structopt(name = "FILE", long = "--output", short = "-o", parse(from_os_str))]
+ #[clap(name = "FILE", long = "output", short = 'o', parse(from_os_str))]
output: PathBuf,
// Set date.
- #[structopt(name = "DATE", long = "--date")]
+ #[clap(name = "DATE", long = "date")]
date: Option<String>,
}
@@ -397,7 +397,7 @@ impl Docgen {
}
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
/// Generate test suites from Subplot documents
///
/// This reads a subplot document, extracts the scenarios, and writes out a test
@@ -406,15 +406,15 @@ struct Codegen {
/// The template to use from the document.
///
/// If not specified, subplot will try and find a unique template name from the document
- #[structopt(name = "TEMPLATE", long = "--template", short = "-t")]
+ #[clap(name = "TEMPLATE", long = "template", short = 't')]
template: Option<String>,
/// Input filename.
- #[structopt(parse(from_os_str))]
+ #[clap(parse(from_os_str))]
filename: PathBuf,
/// Write generated test program to this file.
- #[structopt(
+ #[clap(
long,
short,
parse(from_os_str),
@@ -423,7 +423,7 @@ struct Codegen {
output: PathBuf,
/// Run the generated test program after writing it?
- #[structopt(long, short, help = "Runs generated test program")]
+ #[clap(long, short, help = "Runs generated test program")]
run: bool,
}
@@ -513,11 +513,11 @@ fn print_source_errors(e: Option<&dyn std::error::Error>) {
fn real_main() {
info!("Starting Subplot");
- let argparser = Toplevel::clap();
+ let argparser = Toplevel::command();
let version = long_version().unwrap();
let argparser = argparser.long_version(version.as_str());
let args = argparser.get_matches();
- let args = Toplevel::from_clap(&args);
+ let args = Toplevel::from_arg_matches(&args).unwrap();
args.handle_special_args();
match args.run() {
Ok(_) => {
diff --git a/src/diagrams.rs b/src/diagrams.rs
index 2bdd0ed..6e0b875 100644
--- a/src/diagrams.rs
+++ b/src/diagrams.rs
@@ -7,29 +7,28 @@ use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::sync::Mutex;
+use clap::Parser;
use lazy_static::lazy_static;
-use structopt::StructOpt;
-
-/// Resources used to configure paths for dot, plantuml.jar, and friends
+// Resources used to configure paths for dot, plantuml.jar, and friends
#[allow(missing_docs)]
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct MarkupOpts {
- #[structopt(
+ #[clap(
long = "dot",
help = "Path to the `dot` binary.",
name = "DOTPATH",
env = "SUBPLOT_DOT_PATH"
)]
dot_path: Option<PathBuf>,
- #[structopt(
+ #[clap(
long = "plantuml-jar",
help = "Path to the `plantuml.jar` file.",
name = "PLANTUMLJARPATH",
env = "SUBPLOT_PLANTUML_JAR_PATH"
)]
plantuml_jar_path: Option<PathBuf>,
- #[structopt(
+ #[clap(
long = "java",
help = "Path to Java executable (note, effectively overrides JAVA_HOME if set to an absolute path)",
name = "JAVA_PATH",
diff --git a/src/resource.rs b/src/resource.rs
index 336c4e2..9ac9da8 100644
--- a/src/resource.rs
+++ b/src/resource.rs
@@ -5,19 +5,19 @@
//! binary, from template paths given on the CLI, or from paths built into the
//! binary and present on disk.
+use clap::Parser;
use std::io::{self, Cursor, Read};
use std::path::{Path, PathBuf};
use std::sync::Mutex;
-use structopt::StructOpt;
#[allow(missing_docs)]
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
// Options which relate to resource management
//
// To use this, include them *flat* in your options struct, and then after
// parsing, call the [ResourceOpts::handle()] function.
pub struct ResourceOpts {
- #[structopt(
+ #[clap(
long,
number_of_values = 1,
help = "Look for code templates and other resources in DIR",