diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-05-30 23:29:09 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-05-30 23:29:09 +0100 |
commit | 68b6b819fab3446709f9abe18a6796a10f374906 (patch) | |
tree | b1c78c299b0c333e212f874b570b8ea57ae1efd8 | |
parent | e8c01798fcf220f14c66b0f23fe76cbac047cfbd (diff) | |
download | subplot-68b6b819fab3446709f9abe18a6796a10f374906.tar.gz |
bin: Remove obsolete single-call binaries
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | src/bin/sp-codegen.rs | 74 | ||||
-rw-r--r-- | src/bin/sp-docgen.rs | 123 | ||||
-rw-r--r-- | src/bin/sp-extract.rs | 47 | ||||
-rw-r--r-- | src/bin/sp-meta.rs | 44 |
4 files changed, 0 insertions, 288 deletions
diff --git a/src/bin/sp-codegen.rs b/src/bin/sp-codegen.rs deleted file mode 100644 index 8b32b16..0000000 --- a/src/bin/sp-codegen.rs +++ /dev/null @@ -1,74 +0,0 @@ -use std::path::{Path, PathBuf}; -use std::process::Command; - -use anyhow::Result; -use structopt::StructOpt; - -use subplot::{generate_test_program, resource, template_spec, Style, SubplotError, TemplateSpec}; - -mod cli; - -fn main() -> Result<()> { - match std::env::var("SUBPLOT_PLEASE") { - Ok(s) if s == "1" => {} - _ => { - eprintln!("error: Use of `sp-codegen` is deprecated."); - eprintln!("error: You should use `subplot codegen` instead."); - std::process::exit(1); - } - } - let opt = Opt::from_args(); - - opt.resources.handle(opt.filename.parent()); - let mut doc = cli::load_document(&opt.filename, Style::default())?; - doc.lint()?; - if !doc.check_named_files_exist()? { - eprintln!("Unable to continue"); - std::process::exit(1); - } - - let spec = template_spec(&doc)?; - generate_test_program(&mut doc, &spec, &opt.output)?; - - if opt.run && !run(&spec, &opt.output)? { - eprintln!("Test program failed."); - std::process::exit(1); - } - - Ok(()) -} - -// Define the command line arguments. -#[derive(Debug, StructOpt)] -#[structopt(name = "codegen", about = "Subplot code generator.")] -struct Opt { - // Input filename. - #[structopt(parse(from_os_str))] - filename: PathBuf, - - // Write generated test program to this file. - #[structopt( - long, - short, - parse(from_os_str), - help = "Writes generated test program to FILE" - )] - output: PathBuf, - - // Run the generated test program after writing it? - #[structopt(long, short, help = "Runs generated test program")] - run: bool, - - #[structopt(flatten)] - resources: resource::ResourceOpts, -} - -fn run(spec: &TemplateSpec, filename: &Path) -> subplot::Result<bool> { - let run = match spec.run() { - None => return Err(SubplotError::TemplateNoRun), - Some(x) => x, - }; - - let status = Command::new(run).arg(filename).status()?; - Ok(status.success()) -} diff --git a/src/bin/sp-docgen.rs b/src/bin/sp-docgen.rs deleted file mode 100644 index cdedbfd..0000000 --- a/src/bin/sp-docgen.rs +++ /dev/null @@ -1,123 +0,0 @@ -use chrono::{Local, TimeZone}; -use std::ffi::OsString; -use std::fs; -use std::path::Path; -use std::path::PathBuf; -use std::time::UNIX_EPOCH; -use structopt::StructOpt; - -use anyhow::Result; - -use subplot::{resource, Style}; - -mod cli; - -// Define the command line arguments. -#[derive(Debug, StructOpt)] -#[structopt(name = "docgen", about = "Subplot document generator.")] -struct Opt { - // One or more input filename. - #[structopt(parse(from_os_str))] - filenames: Vec<PathBuf>, - - // Set output file name. - #[structopt(name = "FILE", long = "--output", short = "-o", parse(from_os_str))] - output: PathBuf, - - // Set date. - #[structopt(name = "DATE", long = "--date")] - date: Option<String>, - - #[structopt(flatten)] - resources: resource::ResourceOpts, -} - -fn main() -> Result<()> { - match std::env::var("SUBPLOT_PLEASE") { - Ok(s) if s == "1" => {} - _ => { - eprintln!("error: Use of `sp-codegen` is deprecated."); - eprintln!("error: You should use `subplot codegen` instead."); - std::process::exit(1); - } - } - let opt = Opt::from_args(); - - opt.resources.handle( - opt.filenames - .get(0) - .map(PathBuf::as_path) - .and_then(Path::parent), - ); - let mut pandoc = pandoc::new(); - - let first_file = &opt.filenames[0]; - - let mut style = Style::default(); - if opt.output.extension() == Some(&OsString::from("pdf")) { - style.typeset_links_as_notes(); - } - - let mut doc = cli::load_document(&first_file, style)?; - doc.lint()?; - if !doc.check_named_files_exist()? { - eprintln!("Continuing despite warnings"); - } - - // Metadata date from command line or file mtime. However, we - // can't set it directly, since we don't want to override the date - // in the actual document, if given, so we only set - // user-provided-date. Our parsing code will use that if date is - // not document metadata. - let date = if let Some(date) = opt.date { - date - } else if let Some(date) = doc.meta().date() { - date.to_string() - } else { - mtime_formatted(mtime(first_file)?) - }; - pandoc.add_option(pandoc::PandocOption::Meta("date".to_string(), Some(date))); - pandoc.add_option(pandoc::PandocOption::TableOfContents); - pandoc.add_option(pandoc::PandocOption::Standalone); - pandoc.add_option(pandoc::PandocOption::NumberSections); - - if need_output(&mut doc, &opt.output) { - doc.typeset(); - pandoc.set_input_format(pandoc::InputFormat::Json, vec![]); - pandoc.set_input(pandoc::InputKind::Pipe(doc.ast()?)); - pandoc.set_output(pandoc::OutputKind::File(opt.output.clone())); - pandoc.execute()?; - } - - Ok(()) -} - -fn mtime(filename: &Path) -> Result<(u64, u32)> { - let mtime = fs::metadata(filename)?.modified()?; - let mtime = mtime.duration_since(UNIX_EPOCH)?; - Ok((mtime.as_secs(), mtime.subsec_nanos())) -} - -fn mtime_formatted(mtime: (u64, u32)) -> String { - let secs: i64 = format!("{}", mtime.0).parse().unwrap_or(0); - let dt = Local.timestamp(secs, mtime.1); - dt.format("%Y-%m-%d %H:%M").to_string() -} - -fn need_output(doc: &mut subplot::Document, output: &Path) -> bool { - let output = match mtime(output) { - Err(_) => return true, - Ok(ts) => ts, - }; - - for filename in doc.sources() { - let source = match mtime(&filename) { - Err(_) => return true, - Ok(ts) => ts, - }; - if source >= output { - return true; - } - } - false -} diff --git a/src/bin/sp-extract.rs b/src/bin/sp-extract.rs deleted file mode 100644 index 05a7037..0000000 --- a/src/bin/sp-extract.rs +++ /dev/null @@ -1,47 +0,0 @@ -use anyhow::Result; -use std::fs::write; -use std::path::PathBuf; - -use structopt::StructOpt; - -use subplot::Style; - -mod cli; - -#[derive(Debug, StructOpt)] -#[structopt(name = "sp-meta", about = "Show Subplot document metadata.")] -struct Opt { - /// Input subplot document filename - #[structopt(parse(from_os_str))] - filename: PathBuf, - - /// Names of embedded files to be extracted. - #[structopt()] - embedded: Vec<String>, - - // Set output directory. - #[structopt(name = "DIR", long = "--directory", short = "-d", parse(from_os_str))] - directory: PathBuf, -} - -fn main() -> Result<()> { - match std::env::var("SUBPLOT_PLEASE") { - Ok(s) if s == "1" => {} - _ => { - eprintln!("error: Use of `sp-codegen` is deprecated."); - eprintln!("error: You should use `subplot codegen` instead."); - std::process::exit(1); - } - } - let opt = Opt::from_args(); - - let doc = cli::load_document(&opt.filename, Style::default())?; - - for filename in opt.embedded { - let file = cli::extract_file(&doc, &filename)?; - let output = opt.directory.join(filename); - write(output, file.contents())?; - } - - Ok(()) -} diff --git a/src/bin/sp-meta.rs b/src/bin/sp-meta.rs deleted file mode 100644 index f230157..0000000 --- a/src/bin/sp-meta.rs +++ /dev/null @@ -1,44 +0,0 @@ -use anyhow::Result; -use std::convert::TryFrom; -use std::path::PathBuf; - -use structopt::StructOpt; - -use subplot::Style; - -mod cli; - -use cli::{Metadata, OutputFormat}; - -#[derive(Debug, StructOpt)] -#[structopt(name = "sp-meta", about = "Show Subplot document metadata.")] -struct Opt { - /// Form that you want the output to take - #[structopt(short = "o", default_value = "plain", possible_values=&["plain", "json"])] - output_format: OutputFormat, - /// Input subplot document filename - #[structopt(parse(from_os_str))] - filename: PathBuf, -} - -fn main() -> Result<()> { - match std::env::var("SUBPLOT_PLEASE") { - Ok(s) if s == "1" => {} - _ => { - eprintln!("error: Use of `sp-codegen` is deprecated."); - eprintln!("error: You should use `subplot codegen` instead."); - std::process::exit(1); - } - } - let opt = Opt::from_args(); - - let mut doc = cli::load_document(&opt.filename, Style::default())?; - let meta = Metadata::try_from(&mut doc)?; - - match opt.output_format { - OutputFormat::Plain => meta.write_out(), - OutputFormat::Json => println!("{}", serde_json::to_string_pretty(&meta)?), - } - - Ok(()) -} |