Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"
keywords = ["ufo", "font-format", "glif", "fonts"]

[dependencies]
clap = "2.33.3"
clap = { version = "3.1", features = ["cargo"] }
norad = { git = "https://github.com/linebender/norad" }
serde_json = "1"
unic-ucd = "0.9"
Expand Down
28 changes: 14 additions & 14 deletions src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,49 @@ use std::time::Instant;
use crate::util;
use crate::write_metainfo::write_metainfo_impl;

pub fn clap_subcommand() -> clap::App<'static, 'static> {
clap::SubCommand::with_name("arbitrary")
pub fn clap_subcommand<'help>() -> clap::Command<'help> {
clap::Command::new("arbitrary")
.setting(clap::AppSettings::DeriveDisplayOrder)
.about("Performs arbitrary operations on a plist file, by default a font's fontinfo.plist.\n\nNote: The arguments `-k`, `-v`, and `-d` must be provided multiple times for multiple values, not delimited.")
.version(env!("CARGO_PKG_VERSION"))
.arg(
clap::Arg::with_name("keys")
.required_unless("delete-keys")
.multiple(true)
clap::Arg::new("keys")
.required_unless_present("delete-keys")
.multiple_occurrences(true)
.takes_value(true)
.allow_hyphen_values(true)
.number_of_values(1)
.short("k")
.short('k')
.long("key")
.value_name("key")
.help("List of key values to display, one per line, in order requested"),
)
.arg(
clap::Arg::with_name("values")
.multiple(true)
clap::Arg::new("values")
.multiple_occurrences(true)
.takes_value(true)
.allow_hyphen_values(true)
.number_of_values(1)
.short("v")
.short('v')
.long("value")
.value_name("value")
.help("List of values to write, in order requested"),
)
.arg(
clap::Arg::with_name("delete-keys")
.multiple(true)
clap::Arg::new("delete-keys")
.multiple_occurrences(true)
.takes_value(true)
.allow_hyphen_values(true)
.number_of_values(1)
.short("d")
.short('d')
.long("delete")
.value_name("key")
.help("List of keys to delete from the plist"),
)
.arg(
clap::Arg::with_name("xml-redirect")
clap::Arg::new("xml-redirect")
.takes_value(true)
.short("X")
.short('X')
.long("xml-redirect")
.value_name("FILE")
.help("Redirect XML to this path instead. Use /dev/stdout or /dev/stderr if that's what you want, `-` not recognized.")
Expand Down
18 changes: 9 additions & 9 deletions src/glyphpathlen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ use MFEKmath::{piecewise::SegmentIterator, Piecewise};

use crate::util;

pub fn clap_subcommand() -> clap::App<'static, 'static> {
clap::SubCommand::with_name("glyphpathlen")
pub fn clap_subcommand<'help>() -> clap::Command<'help> {
clap::Command::new("glyphpathlen")
.setting(clap::AppSettings::DeriveDisplayOrder)
.about("Show length of contours in a glyph (.glif) on separate lines")
.arg(
clap::Arg::with_name("segmentwise")
.short("s")
clap::Arg::new("segmentwise")
.short('s')
.long("segmentwise")
.help("Display length of each segment separated by spaces"),
)
.arg(
clap::Arg::with_name("joined")
clap::Arg::new("joined")
.long("joined")
.short("j")
.short('j')
.help("Display one line: sum of joined path"),
)
.arg(clap::Arg::with_name("json").long("json").short("J").help("Output JSON instead"))
.arg(clap::Arg::new("json").long("json").short('J').help("Output JSON instead"))
.arg(
clap::Arg::with_name("accuracy")
clap::Arg::new("accuracy")
.long("accuracy")
.help("Precision of length calculation")
.takes_value(true)
.default_value("0.01")
.empty_values(false)
.forbid_empty_values(true)
.number_of_values(1)
.validator(util::arg_validator_positive_f64),
)
Expand Down
18 changes: 9 additions & 9 deletions src/glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ use unic_ucd::name::Name;

use std::cmp::Ordering;

pub fn clap_subcommands() -> [clap::App<'static, 'static>; 2] {
pub fn clap_subcommands<'help>() -> [clap::Command<'help>; 2] {
[
clap::SubCommand::with_name("glyphs")
clap::Command::new("glyphs")
.about("Dumps the font's glyphs")
.setting(clap::AppSettings::DeriveDisplayOrder)
.arg(
clap::Arg::with_name("sort")
clap::Arg::new("sort")
.takes_value(false)
.short("s")
.short('s')
.long("sort")
.help("Sort by Unicode char"),
)
.arg(
clap::Arg::with_name("hide-unencoded")
clap::Arg::new("hide-unencoded")
.takes_value(false)
.short("H")
.short('H')
.long("hide-unencoded")
.help("Don't show unencoded glyphs in listing"),
)
.arg(
clap::Arg::with_name("unencoded-at-top")
clap::Arg::new("unencoded-at-top")
.takes_value(false)
.short("u")
.short('u')
.long("unencoded-at-top")
.help("Glyphs without encodings go to the top"),
),
clap::SubCommand::with_name("glyph").about("Dumps a single font glyph in the format of `MFEKmetadata glyphs`"),
clap::Command::new("glyph").about("Dumps a single font glyph in the format of `MFEKmetadata glyphs`"),
]
}

Expand Down
4 changes: 2 additions & 2 deletions src/glyphslen.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use clap;
use norad::{DataRequest, Font};

pub fn clap_subcommand() -> clap::App<'static, 'static> {
clap::SubCommand::with_name("glyphslen").about("Show number of glyphs in font")
pub fn clap_subcommand<'help>() -> clap::Command<'help> {
clap::Command::new("glyphslen").about("Show number of glyphs in font")
}

pub fn glyphslen(path: &std::ffi::OsStr, _args: &clap::ArgMatches) {
Expand Down
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ pub mod util;

use std::path;

fn parse_args() -> clap::ArgMatches<'static> {
let mut app = clap::App::new(clap::crate_name!())
fn parse_args() -> clap::ArgMatches {
let mut app = clap::Command::new(clap::crate_name!())
.version(env!("CARGO_PKG_VERSION"))
.author(clap::crate_authors!())
.about(clap::crate_description!())
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommand_required(true)
.arg_required_else_help(true)
.arg(
clap::Arg::with_name("PATH")
clap::Arg::new("PATH")
.help("Sets the input file (glif/UFO/rarely plist) to use")
.required(true)
.index(1)
Expand Down Expand Up @@ -59,12 +60,10 @@ fn main() {
util::init_env_logger();
mfek_ipc::display_header("metadata");
let matches = parse_args();
let (program, args) = matches.subcommand();
let (program, args) = matches.subcommand().expect("Failed to parse args?");

let path = matches.value_of_os("PATH").unwrap();

let args = args.expect("Failed to parse args?");

match program {
"arbitrary" => arbitrary(path, &args),
"glyphs" => glyphs(path, &args),
Expand Down
16 changes: 8 additions & 8 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum ValidatorRange {
Positive,
}

fn arg_validator_f64_impl(v: String, range: ValidatorRange) -> Result<(), String> {
fn arg_validator_f64_impl(v: &str, range: ValidatorRange) -> Result<(), String> {
match v.parse::<f64>() {
Ok(i) => {
let err = || Err(String::from(&format!("Value outside allowed range ({:?})", range)));
Expand All @@ -36,38 +36,38 @@ fn arg_validator_f64_impl(v: String, range: ValidatorRange) -> Result<(), String
}
}

pub fn arg_validator_positive_f64(v: String) -> Result<(), String> {
pub fn arg_validator_positive_f64(v: &str) -> Result<(), String> {
arg_validator_f64_impl(v, ValidatorRange::Positive)
}

pub fn arg_validator_positive_or_zero_f64(v: String) -> Result<(), String> {
pub fn arg_validator_positive_or_zero_f64(v: &str) -> Result<(), String> {
arg_validator_f64_impl(v, ValidatorRange::PositiveNotZero)
}

pub fn arg_validator_f64(v: String) -> Result<(), String> {
pub fn arg_validator_f64(v: &str) -> Result<(), String> {
arg_validator_f64_impl(v, ValidatorRange::All)
}

pub fn arg_validator_isize(v: String) -> Result<(), String> {
pub fn arg_validator_isize(v: &str) -> Result<(), String> {
match v.parse::<isize>() {
Ok(_) => Ok(()),
Err(_) => Err(String::from("Value must be an integer")),
}
}

pub fn arg_validator_usize(v: String) -> Result<(), String> {
pub fn arg_validator_usize(v: &str) -> Result<(), String> {
match v.parse::<isize>() {
Ok(_) => Ok(()),
Err(_) => Err(String::from("Value must be a positive integer")),
}
}

pub fn arg_validator_suffix(f: &impl Fn(String) -> Result<(), String>, suffix: char) -> impl Fn(String) -> Result<(), String> + '_ {
pub fn arg_validator_suffix(f: &impl Fn(&str) -> Result<(), String>, suffix: char) -> impl Fn(String) -> Result<(), String> + '_ {
move |mut v| {
while v.ends_with(suffix) {
assert_eq!(v.pop().unwrap(), suffix);
}
f(v)
f(&v)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/write_metainfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ static METAINFO: &[u8] = br#"<?xml version="1.0" encoding="UTF-8"?>
</dict>
</plist>"#;

pub fn clap_subcommand() -> clap::App<'static, 'static> {
clap::SubCommand::with_name("write_metainfo")
pub fn clap_subcommand<'help>() -> clap::Command<'help> {
clap::Command::new("write_metainfo")
}

pub(crate) fn write_metainfo_impl(ufo: &OsStr) -> Result<path::PathBuf, io::Error> {
Expand Down