forked from tforgione/md2pdf
Upgrade clap to v4
This commit is contained in:
25
src/main.rs
25
src/main.rs
@@ -2,7 +2,7 @@ use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::process::exit;
|
||||
|
||||
use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg};
|
||||
use clap::{crate_authors, crate_description, crate_name, crate_version, Command, Arg};
|
||||
|
||||
use md2pdf::{markdown_to_latex, markdown_to_pdf};
|
||||
|
||||
@@ -20,30 +20,33 @@ macro_rules! unwrap {
|
||||
|
||||
fn main() {
|
||||
|
||||
let matches = App::new(crate_name!())
|
||||
let matches = Command::new(crate_name!())
|
||||
.bin_name(crate_name!())
|
||||
.version(crate_version!())
|
||||
.author(crate_authors!("\n"))
|
||||
.about(crate_description!())
|
||||
.arg(Arg::with_name("INPUT")
|
||||
.arg(Arg::new("INPUT")
|
||||
.long("input")
|
||||
.short("i")
|
||||
.short('i')
|
||||
.help("Input markdown files")
|
||||
.required(true)
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("OUTPUT")
|
||||
.value_parser(clap::value_parser!(std::path::PathBuf))
|
||||
)
|
||||
.arg(Arg::new("OUTPUT")
|
||||
.long("output")
|
||||
.short("o")
|
||||
.short('o')
|
||||
.help("Output tex or pdf file")
|
||||
.required(true)
|
||||
.takes_value(true))
|
||||
.value_parser(clap::value_parser!(std::path::PathBuf))
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let input_path = matches.get_one::<std::path::PathBuf>("INPUT").unwrap();
|
||||
let mut content = String::new();
|
||||
let mut input = unwrap!(File::open(matches.value_of("INPUT").unwrap()), "couldn't open input file");
|
||||
let mut input = unwrap!(File::open(input_path), "couldn't open input file");
|
||||
unwrap!(input.read_to_string(&mut content), "couldn't read file content");
|
||||
|
||||
let output_path = matches.value_of("OUTPUT").unwrap();
|
||||
let output_path = matches.get_one::<std::path::PathBuf>("OUTPUT").unwrap();
|
||||
let mut output = unwrap!(File::create(output_path), "couldn't open output file");
|
||||
|
||||
if output_path.ends_with(".tex") {
|
||||
@@ -53,7 +56,7 @@ fn main() {
|
||||
let data = unwrap!(markdown_to_pdf(content), "error while compiling latex, this is most likely a bug");
|
||||
unwrap!(output.write(&data), "coudln't write output file");
|
||||
} else {
|
||||
eprintln!("unknown file format for output: {}", output_path);
|
||||
eprintln!("unknown file format for output: {}", output_path.display());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user