mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-25 18:49:50 -04:00
FEATURE: Default to printing out our help if no subcommand is used.
This commit is contained in:
parent
cbd767d81b
commit
0003e1b9c3
52
src/main.rs
52
src/main.rs
@ -30,7 +30,7 @@ use ucglib::convert::traits;
|
||||
use ucglib::convert::ConverterRegistry;
|
||||
|
||||
// TODO(jwall): List the target output types automatically.
|
||||
fn do_flags<'a>() -> clap::ArgMatches<'a> {
|
||||
fn do_flags<'a, 'b>() -> clap::App<'a, 'b> {
|
||||
clap_app!(
|
||||
ucg =>
|
||||
(version: crate_version!())
|
||||
@ -55,7 +55,7 @@ fn do_flags<'a>() -> clap::ArgMatches<'a> {
|
||||
(@subcommand converters =>
|
||||
(about: "list the available converters")
|
||||
)
|
||||
).get_matches()
|
||||
)
|
||||
}
|
||||
|
||||
fn run_converter(c: &traits::Converter, v: Rc<Val>, f: Option<&str>) -> traits::Result {
|
||||
@ -201,11 +201,11 @@ fn visit_ucg_files(
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let app = do_flags();
|
||||
let cache: Rc<RefCell<Cache>> = Rc::new(RefCell::new(MemoryCache::new()));
|
||||
let registry = ConverterRegistry::make_registry();
|
||||
if let Some(matches) = app.subcommand_matches("inspect") {
|
||||
fn inspect_command(
|
||||
matches: &clap::ArgMatches,
|
||||
cache: Rc<RefCell<Cache>>,
|
||||
registry: &ConverterRegistry,
|
||||
) {
|
||||
let file = matches.value_of("INPUT").unwrap();
|
||||
let sym = matches.value_of("sym");
|
||||
let target = matches.value_of("target").unwrap();
|
||||
@ -241,7 +241,13 @@ fn main() {
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
} else if let Some(matches) = app.subcommand_matches("build") {
|
||||
}
|
||||
|
||||
fn build_command(
|
||||
matches: &clap::ArgMatches,
|
||||
cache: Rc<RefCell<Cache>>,
|
||||
registry: &ConverterRegistry,
|
||||
) {
|
||||
let files = matches.values_of("INPUT");
|
||||
let recurse = matches.is_present("recurse");
|
||||
let mut ok = true;
|
||||
@ -261,7 +267,13 @@ fn main() {
|
||||
if !ok {
|
||||
process::exit(1)
|
||||
}
|
||||
} else if let Some(matches) = app.subcommand_matches("test") {
|
||||
}
|
||||
|
||||
fn test_command(
|
||||
matches: &clap::ArgMatches,
|
||||
cache: Rc<RefCell<Cache>>,
|
||||
registry: &ConverterRegistry,
|
||||
) {
|
||||
let files = matches.values_of("INPUT");
|
||||
let recurse = matches.is_present("recurse");
|
||||
if files.is_none() {
|
||||
@ -286,7 +298,9 @@ fn main() {
|
||||
}
|
||||
}
|
||||
process::exit(0);
|
||||
} else if let Some(_todo) = app.subcommand_matches("converters") {
|
||||
}
|
||||
|
||||
fn converters_command(registry: &ConverterRegistry) {
|
||||
println!("Available converters:");
|
||||
println!("");
|
||||
for (name, c) in registry.get_converter_list().iter() {
|
||||
@ -295,5 +309,23 @@ fn main() {
|
||||
println!(" Output Extension: `.{}`", c.file_ext());
|
||||
println!("");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut app = do_flags();
|
||||
let app_matches = app.clone().get_matches();
|
||||
let cache: Rc<RefCell<Cache>> = Rc::new(RefCell::new(MemoryCache::new()));
|
||||
let registry = ConverterRegistry::make_registry();
|
||||
if let Some(matches) = app_matches.subcommand_matches("inspect") {
|
||||
inspect_command(matches, cache, ®istry);
|
||||
} else if let Some(matches) = app_matches.subcommand_matches("build") {
|
||||
build_command(matches, cache, ®istry);
|
||||
} else if let Some(matches) = app_matches.subcommand_matches("test") {
|
||||
test_command(matches, cache, ®istry);
|
||||
} else if let Some(_) = app_matches.subcommand_matches("converters") {
|
||||
converters_command(®istry)
|
||||
} else {
|
||||
app.print_help().unwrap();
|
||||
println!("");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user