diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/subplot.rs | 70 | ||||
-rw-r--r-- | src/diagrams.rs | 13 | ||||
-rw-r--r-- | src/resource.rs | 6 |
3 files changed, 44 insertions, 45 deletions
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", |