Skip to content

Instantly share code, notes, and snippets.

@ctrlcctrlv
Created October 25, 2021 14:15
Show Gist options
  • Select an option

  • Save ctrlcctrlv/bd0ba2d2a9eb638eec5b5f9dd0ec671e to your computer and use it in GitHub Desktop.

Select an option

Save ctrlcctrlv/bd0ba2d2a9eb638eec5b5f9dd0ec671e to your computer and use it in GitHub Desktop.
Solution to clap issue #1820 (having an argument that is both a flag and positional)
use clap::{self, App, AppSettings, Arg};
fn main() {
let matches = App::new("glif2svg")
.setting(AppSettings::ArgRequiredElseHelp)
.version("0.1.0")
.author("Fredrick R. Brennan <copypasteⒶkittens⊙ph>; MFEK Authors")
.about("Convert between glif to SVG")
.arg(Arg::with_name("input_file")
.short("in")
.long("input")
.takes_value(true)
.conflicts_with("input")
.hidden(true))
.arg(Arg::with_name("input")
.index(1)
.help("The path to the input file.")
.conflicts_with("input_file")
.required_unless("input_file"))
.arg(Arg::with_name("output_file")
.short("out")
.long("output")
.takes_value(true)
.conflicts_with("output")
.required_unless("output")
.display_order(1)
.help("The path to the output file.\n\n\n"))
.arg(Arg::with_name("output")
.index(2)
.hidden(true))
.arg(Arg::with_name("no-transform")
.short("T")
.long("no-transform")
.help("Don't put transform=\"translate(…)\" in SVG"))
.arg(Arg::with_name("no-glif-metrics")
.short("M")
.long("no-glif-metrics")
.help("Don't consider glif's height/width when writing SVG, use minx/maxx/miny/maxy"))
.arg(Arg::with_name("fontinfo")
.short("F")
.long("fontinfo")
.takes_value(true)
.help("fontinfo file (for metrics, should point to fontinfo.plist path)\n\n"))
.get_matches();
let input = matches.value_of("input").unwrap_or_else(||matches.value_of("input_file").unwrap());
//let glif: glifparser::Glif<()> = glifparser::glif::read_from_filename(matches.value_of("input").unwrap()).unwrap();
eprintln!("Input: {}", input);
eprintln!("{:?}", matches);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment