Upgrade clap to v4

This commit is contained in:
William Desportes 2022-10-01 14:00:37 +02:00
parent e15c3da583
commit 9c1a0dae88
Signed by: williamdes
GPG Key ID: 90A0EF1B8251A889
3 changed files with 46 additions and 14 deletions

33
Cargo.lock generated
View File

@ -181,6 +181,29 @@ dependencies = [
"vec_map", "vec_map",
] ]
[[package]]
name = "clap"
version = "4.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a1af219c3e254a8b4649d6ddaef886b2015089f35f2ac5e1db31410c0566ab8"
dependencies = [
"atty",
"bitflags",
"clap_lex",
"once_cell",
"strsim 0.10.0",
"termcolor",
]
[[package]]
name = "clap_lex"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
dependencies = [
"os_str_bytes",
]
[[package]] [[package]]
name = "clearscreen" name = "clearscreen"
version = "1.0.10" version = "1.0.10"
@ -881,7 +904,7 @@ dependencies = [
name = "md2pdf" name = "md2pdf"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"clap", "clap 4.0.7",
"pulldown-cmark", "pulldown-cmark",
"tectonic", "tectonic",
] ]
@ -1144,6 +1167,12 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "os_str_bytes"
version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]] [[package]]
name = "pathdiff" name = "pathdiff"
version = "0.2.1" version = "0.2.1"
@ -1559,7 +1588,7 @@ version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
dependencies = [ dependencies = [
"clap", "clap 2.34.0",
"lazy_static", "lazy_static",
"structopt-derive", "structopt-derive",
] ]

View File

@ -14,4 +14,4 @@ cargo = "1.64"
[dependencies] [dependencies]
tectonic = "0.5.2" tectonic = "0.5.2"
pulldown-cmark = "0.5.3" pulldown-cmark = "0.5.3"
clap = "2.34.0" clap = { version = "4.0.7", features = ["cargo"] }

View File

@ -2,7 +2,7 @@ use std::fs::File;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::process::exit; 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}; use md2pdf::{markdown_to_latex, markdown_to_pdf};
@ -20,30 +20,33 @@ macro_rules! unwrap {
fn main() { fn main() {
let matches = App::new(crate_name!()) let matches = Command::new(crate_name!())
.bin_name(crate_name!()) .bin_name(crate_name!())
.version(crate_version!()) .version(crate_version!())
.author(crate_authors!("\n")) .author(crate_authors!("\n"))
.about(crate_description!()) .about(crate_description!())
.arg(Arg::with_name("INPUT") .arg(Arg::new("INPUT")
.long("input") .long("input")
.short("i") .short('i')
.help("Input markdown files") .help("Input markdown files")
.required(true) .required(true)
.takes_value(true)) .value_parser(clap::value_parser!(std::path::PathBuf))
.arg(Arg::with_name("OUTPUT") )
.arg(Arg::new("OUTPUT")
.long("output") .long("output")
.short("o") .short('o')
.help("Output tex or pdf file") .help("Output tex or pdf file")
.required(true) .required(true)
.takes_value(true)) .value_parser(clap::value_parser!(std::path::PathBuf))
)
.get_matches(); .get_matches();
let input_path = matches.get_one::<std::path::PathBuf>("INPUT").unwrap();
let mut content = String::new(); 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"); 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"); let mut output = unwrap!(File::create(output_path), "couldn't open output file");
if output_path.ends_with(".tex") { 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"); 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"); unwrap!(output.write(&data), "coudln't write output file");
} else { } else {
eprintln!("unknown file format for output: {}", output_path); eprintln!("unknown file format for output: {}", output_path.display());
exit(1); exit(1);
} }