From 03d69ede42c741e0387f0d441ed9047d7d644fd1 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Mon, 7 Jan 2019 19:50:15 -0600 Subject: [PATCH] FEATURE: Allow the inpsect command to process full expressions. Related to #22 --- src/main.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 10ac7cd..66119a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ fn do_flags<'a, 'b>() -> clap::App<'a, 'b> { (@arg nostrict: --("no-strict") "Turn off strict checking.") (@subcommand inspect => (about: "Inspect a specific symbol in a ucg file.") - (@arg sym: --sym +takes_value +required "Specify a specific binding in the ucg file to output.") + (@arg expr: --expr +takes_value +required "Specify a specific binding in the ucg file to output.") (@arg target: --format +required +takes_value "Inspect output type. (flags, json, env, exec)") (@arg INPUT: +required "Input ucg file to inspect symbol from.") ) @@ -244,7 +244,7 @@ fn inspect_command( strict: bool, ) { let file = matches.value_of("INPUT").unwrap(); - let sym = matches.value_of("sym"); + let sym = matches.value_of("expr"); let target = matches.value_of("target").unwrap(); let mut builder = build::FileBuilder::new(file, import_paths, cache); builder.set_strict(strict); @@ -257,7 +257,22 @@ fn inspect_command( process::exit(1); } let val = match sym { - Some(sym_name) => builder.get_out_by_name(sym_name), + Some(sym_name) => { + let normalized = if !sym_name.ends_with(";") { + let mut temp = sym_name.to_owned(); + temp.push_str(";"); + temp + } else { + sym_name.to_owned() + }; + match builder.eval_string(&normalized) { + Ok(v) => Some(v.clone()), + Err(e) => { + eprintln!("Err: {}", e); + process::exit(1); + } + } + } None => builder.last, }; match val {