diff options
author | Lukáš Tyrychtr <lukastyrychtr@gmail.com> | 2022-10-20 22:10:18 +0200 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2022-11-04 14:14:38 -0600 |
commit | 8a1319d26f7c88f31a0bb462b3fffa6ff0be14f3 (patch) | |
tree | ffe1c7aceafcb99f6d157e20694c3f785f8a98c6 | |
parent | e276654de2468f830853d462d5a17fe6dfe75cdc (diff) | |
download | librsvg-8a1319d26f7c88f31a0bb462b3fffa6ff0be14f3.tar.gz |
Update to clap 4
Fixes #908
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/765>
-rw-r--r-- | Cargo.lock | 40 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/bin/rsvg-convert.rs | 182 |
3 files changed, 119 insertions, 105 deletions
@@ -209,32 +209,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "bitflags", - "textwrap 0.11.0", + "textwrap", "unicode-width", ] [[package]] name = "clap" -version = "3.2.22" +version = "4.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +checksum = "06badb543e734a2d6568e19a40af66ed5364360b9226184926f89d229b4b4267" dependencies = [ "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", "once_cell", "strsim", "termcolor", - "textwrap 0.15.1", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad" dependencies = [ "heck", "proc-macro-error", @@ -245,9 +243,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -869,12 +867,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] name = "heck" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -924,16 +916,6 @@ dependencies = [ ] [[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1000,7 +982,7 @@ dependencies = [ "cairo-rs", "cast", "chrono", - "clap 3.2.22", + "clap 4.0.17", "criterion", "cssparser", "data-url", @@ -2271,12 +2253,6 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" - -[[package]] name = "thiserror" version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -55,7 +55,7 @@ byteorder = "1.4" cairo-rs = { version = "0.16", features=["v1_16", "png", "pdf", "ps", "svg"] } cast = "0.3.0" chrono = "0.4.0" # rsvg-convert -clap = { version = "3.2.22", features = ["cargo", "derive"] } # rsvg-convert +clap = { version = "4.0.17", features = ["cargo", "derive"] } # rsvg-convert cssparser = "0.28.0" data-url = "0.1" encoding = "0.2.33" diff --git a/src/bin/rsvg-convert.rs b/src/bin/rsvg-convert.rs index 3a220729..a69ad91b 100644 --- a/src/bin/rsvg-convert.rs +++ b/src/bin/rsvg-convert.rs @@ -786,193 +786,231 @@ fn parse_args() -> Result<Converter, Error> { let app = clap::Command::new("rsvg-convert") .version(concat!("version ", crate_version!())) .about("Convert SVG files to other image formats") - .help_short('?') - .version_short('v') + .disable_version_flag(true) + .disable_help_flag(true) .arg( - clap::Arg::with_name("res_x") + clap::Arg::new("help") + .short('h') + .short('?') + .long("help") + .help("Display the help") + .action(clap::ArgAction::Help) + ) + .arg( + clap::Arg::new("version") + .short('v') + .long("version") + .help("Display the version information") + .action(clap::ArgAction::Version) + ) + .arg( + clap::Arg::new("res_x") .short('d') .long("dpi-x") - .takes_value(true) + .num_args(1) .value_name("number") .default_value("96") .value_parser(parse_resolution) - .help("Pixels per inch"), + .help("Pixels per inch") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("res_y") + clap::Arg::new("res_y") .short('p') .long("dpi-y") - .takes_value(true) + .num_args(1) .value_name("number") .default_value("96") .value_parser(parse_resolution) - .help("Pixels per inch"), + .help("Pixels per inch") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("zoom_x") + clap::Arg::new("zoom_x") .short('x') .long("x-zoom") - .takes_value(true) + .num_args(1) .value_name("number") .conflicts_with("zoom") .value_parser(parse_zoom_factor) - .help("Horizontal zoom factor"), + .help("Horizontal zoom factor") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("zoom_y") + clap::Arg::new("zoom_y") .short('y') .long("y-zoom") - .takes_value(true) + .num_args(1) .value_name("number") .conflicts_with("zoom") .value_parser(parse_zoom_factor) - .help("Vertical zoom factor"), + .help("Vertical zoom factor") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("zoom") + clap::Arg::new("zoom") .short('z') .long("zoom") - .takes_value(true) + .num_args(1) .value_name("number") .value_parser(parse_zoom_factor) - .help("Zoom factor"), + .help("Zoom factor") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("size_x") + clap::Arg::new("size_x") .short('w') .long("width") - .takes_value(true) + .num_args(1) .value_name("length") .value_parser(parse_length::<Horizontal, Unsigned>) - .help("Width [defaults to the width of the SVG]"), + .help("Width [defaults to the width of the SVG]") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("size_y") + clap::Arg::new("size_y") .short('h') .long("height") - .takes_value(true) + .num_args(1) .value_name("length") .value_parser(parse_length::<Vertical, Unsigned>) - .help("Height [defaults to the height of the SVG]"), + .help("Height [defaults to the height of the SVG]") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("top") + clap::Arg::new("top") .long("top") - .takes_value(true) + .num_args(1) .value_name("length") .value_parser(parse_length::<Vertical, Signed>) - .help("Distance between top edge of page and the image [defaults to 0]"), + .help("Distance between top edge of page and the image [defaults to 0]") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("left") + clap::Arg::new("left") .long("left") - .takes_value(true) + .num_args(1) .value_name("length") .value_parser(parse_length::<Horizontal, Signed>) - .help("Distance between left edge of page and the image [defaults to 0]"), + .help("Distance between left edge of page and the image [defaults to 0]") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("page_width") + clap::Arg::new("page_width") .long("page-width") - .takes_value(true) + .num_args(1) .value_name("length") .value_parser(parse_length::<Horizontal, Unsigned>) - .help("Width of output media [defaults to the width of the SVG]"), + .help("Width of output media [defaults to the width of the SVG]") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("page_height") + clap::Arg::new("page_height") .long("page-height") - .takes_value(true) + .num_args(1) .value_name("length") .value_parser(parse_length::<Vertical, Unsigned>) - .help("Height of output media [defaults to the height of the SVG]"), + .help("Height of output media [defaults to the height of the SVG]") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("format") + clap::Arg::new("format") .short('f') .long("format") - .takes_value(true) - .possible_values(supported_formats.as_slice()) + .num_args(1) + .value_parser(clap::builder::PossibleValuesParser::new(supported_formats.as_slice())) .ignore_case(true) .default_value("png") - .help("Output format"), + .help("Output format") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("output") + clap::Arg::new("output") .short('o') .long("output") - .takes_value(true) + .num_args(1) .value_parser(clap::value_parser!(PathBuf)) - .help("Output filename [defaults to stdout]"), + .help("Output filename [defaults to stdout]") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("export_id") + clap::Arg::new("export_id") .short('i') .long("export-id") - .empty_values(false) + .value_parser(clap::builder::NonEmptyStringValueParser::new()) .value_name("object id") - .help("SVG id of object to export [default is to export all objects]"), + .help("SVG id of object to export [default is to export all objects]") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("accept-language") + clap::Arg::new("accept-language") .short('l') .long("accept-language") - .empty_values(false) + .value_parser(clap::builder::NonEmptyStringValueParser::new()) .value_name("languages") - .help("Languages to accept, for example \"es-MX,de,en\" [default uses language from the environment]"), + .help("Languages to accept, for example \"es-MX,de,en\" [default uses language from the environment]") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("keep_aspect") + clap::Arg::new("keep_aspect") .short('a') .long("keep-aspect-ratio") - .help("Preserve the aspect ratio"), + .help("Preserve the aspect ratio") + .action(clap::ArgAction::SetTrue), ) .arg( - clap::Arg::with_name("background") + clap::Arg::new("background") .short('b') .long("background-color") - .takes_value(true) + .num_args(1) .value_name("color") .value_parser(clap::builder::NonEmptyStringValueParser::new()) .default_value("none") - .help("Set the background color using a CSS color spec"), + .help("Set the background color using a CSS color spec") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("stylesheet") + clap::Arg::new("stylesheet") .short('s') .long("stylesheet") - .takes_value(true) + .num_args(1) .value_parser(clap::value_parser!(PathBuf)) .value_name("filename.css") - .help("Filename of CSS stylesheet to apply"), + .help("Filename of CSS stylesheet to apply") + .action(clap::ArgAction::Set), ) .arg( - clap::Arg::with_name("unlimited") + clap::Arg::new("unlimited") .short('u') .long("unlimited") - .help("Allow huge SVG files"), + .help("Allow huge SVG files") + .action(clap::ArgAction::SetTrue), ) .arg( - clap::Arg::with_name("keep_image_data") + clap::Arg::new("keep_image_data") .long("keep-image-data") - .help("Keep image data"), + .help("Keep image data") + .action(clap::ArgAction::SetTrue), ) .arg( - clap::Arg::with_name("no_keep_image_data") + clap::Arg::new("no_keep_image_data") .long("no-keep-image-data") - .help("Do not keep image data"), + .help("Do not keep image data") + .action(clap::ArgAction::SetFalse), ) .arg( - clap::Arg::with_name("testing") + clap::Arg::new("testing") .long("testing") .help("Render images for librsvg's test suite") - .hidden(true), + .hide(true) + .action(clap::ArgAction::SetTrue), ) .arg( - clap::Arg::with_name("FILE") + clap::Arg::new("FILE") .value_parser(clap::value_parser!(OsString)) .help("The input file(s) to convert") - .multiple(true), + .num_args(1..) + .action(clap::ArgAction::Append), ); let matches = app.get_matches(); @@ -1002,7 +1040,7 @@ fn parse_args() -> Result<Converter, Error> { .map(Language::AcceptLanguage) .map_err(|e| { let desc = format!("{}", e); - clap::Error::with_description(desc, clap::ErrorKind::InvalidValue) + clap::Error::raw(clap::error::ErrorKind::InvalidValue, desc) })?, }; @@ -1010,7 +1048,7 @@ fn parse_args() -> Result<Converter, Error> { .get_one("background") .expect("already provided default_value"); let background_color: Option<Color> = parse_background_color(&**background_str) - .map_err(|e| clap::Error::with_description(e, clap::ErrorKind::InvalidValue))?; + .map_err(|e| clap::Error::raw(clap::error::ErrorKind::InvalidValue, e))?; // librsvg expects ids starting with '#', so it can lookup ids in externs like "subfile.svg#subid". // For the user's convenience, we prepend '#' automatically; we only support specifying ids from @@ -1053,7 +1091,7 @@ fn parse_args() -> Result<Converter, Error> { let zoom_x: Option<ZoomFactor> = matches.get_one("zoom_x").copied(); let zoom_y: Option<ZoomFactor> = matches.get_one("zoom_y").copied(); - let input = match matches.values_of_os("FILE") { + let input = match matches.get_many::<std::ffi::OsString>("FILE") { Some(values) => values .map(|f| PathOrUrl::from_os_str(f).map_err(Error)) .map(|r| r.map(Input::Named)) @@ -1097,7 +1135,7 @@ fn parse_args() -> Result<Converter, Error> { language, input, output, - testing: matches.is_present("testing"), + testing: matches.get_flag("testing"), }) } @@ -1141,8 +1179,8 @@ impl<T> NotFound for Result<T, clap::Error> { /// arguments. fn or_none(self) -> Result<Option<T>, clap::Error> { self.map_or_else( - |e| match e.kind { - clap::ErrorKind::ArgumentNotFound => Ok(None), + |e| match e.kind() { + clap::error::ErrorKind::UnknownArgument => Ok(None), _ => Err(e), }, |v| Ok(Some(v)), |