From 37d304a6f95b8488d45f9adcc0c8742d3b121d2f Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 14 May 2022 14:20:44 +0100 Subject: (cli): Change from structopt to clap3-derive Signed-off-by: Daniel Silverstone --- src/bin/subplot.rs | 70 +++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/bin/subplot.rs') 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 { 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, - #[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, - #[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, } @@ -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, // 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, } @@ -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, /// 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(_) => { -- cgit v1.2.1