mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-21 18:10:42 -04:00
FEATURE: change inspect to eval
Also make it easier to use by having sane defaults for the arguments.
This commit is contained in:
parent
4d6fd87c3d
commit
28129ba1de
18
README.md
18
README.md
@ -32,17 +32,21 @@ Running ucg help will show the following output.
|
||||
Universal Configuration Grammar compiler.
|
||||
|
||||
USAGE:
|
||||
ucg [SUBCOMMAND]
|
||||
ucg [FLAGS] [SUBCOMMAND]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Prints help information
|
||||
-V, --version Prints version information
|
||||
-h, --help Prints help information
|
||||
--no-strict Turn off strict checking.
|
||||
-V, --version Prints version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
build Build a specific ucg file.
|
||||
help Prints this message or the help of the given subcommand(s)
|
||||
inspect Inspect a specific symbol in a ucg file.
|
||||
test Check a specific ucg file for errors.
|
||||
build Build a list of ucg files.
|
||||
converters list the available converters
|
||||
env Describe the environment variables ucg uses.
|
||||
eval Evaluate an expression with an optional ucg file as context.
|
||||
help Prints this message or the help of the given subcommand(s)
|
||||
importers list the available importers for includes
|
||||
test Check a list of ucg files for errors and run test assertions.
|
||||
```
|
||||
|
||||
## Compiling
|
||||
|
25
src/main.rs
25
src/main.rs
@ -37,11 +37,11 @@ fn do_flags<'a, 'b>() -> clap::App<'a, 'b> {
|
||||
(author: crate_authors!())
|
||||
(about: "Universal Configuration Grammar compiler.")
|
||||
(@arg nostrict: --("no-strict") "Turn off strict checking.")
|
||||
(@subcommand inspect =>
|
||||
(about: "Inspect a specific symbol in a ucg file.")
|
||||
(@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.")
|
||||
(@subcommand eval =>
|
||||
(about: "Evaluate an expression with an optional ucg file as context.")
|
||||
(@arg expr: --expr -e +takes_value +required "Expression to evaluate.")
|
||||
(@arg target: --format +takes_value "Output type. (flags, json, env, exec) defaults to json.")
|
||||
(@arg INPUT: "ucg file to use as context for the expression.")
|
||||
)
|
||||
(@subcommand build =>
|
||||
(about: "Build a list of ucg files.")
|
||||
@ -244,9 +244,9 @@ fn inspect_command(
|
||||
registry: &ConverterRegistry,
|
||||
strict: bool,
|
||||
) {
|
||||
let file = matches.value_of("INPUT").unwrap();
|
||||
let file = matches.value_of("INPUT").unwrap_or("std/functional.ucg");
|
||||
let sym = matches.value_of("expr");
|
||||
let target = matches.value_of("target").unwrap();
|
||||
let target = matches.value_of("target").unwrap_or("json");
|
||||
let mut builder =
|
||||
build::FileBuilder::new(std::env::current_dir().unwrap(), import_paths, cache);
|
||||
builder.set_strict(strict);
|
||||
@ -282,17 +282,20 @@ fn inspect_command(
|
||||
Some(value) => {
|
||||
// We use None here because we always output to stdout for an inspect.
|
||||
run_converter(converter, value, None).unwrap();
|
||||
eprintln!("Build successful");
|
||||
println!("");
|
||||
process::exit(0);
|
||||
}
|
||||
None => {
|
||||
eprintln!("Build results in no value.");
|
||||
eprintln!("No value.");
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
eprintln!("No such converter {}", target);
|
||||
eprintln!(
|
||||
"No such format {}\nrun `ucg converters` to see available formats.",
|
||||
target
|
||||
);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@ -448,7 +451,7 @@ fn main() {
|
||||
} else {
|
||||
true
|
||||
};
|
||||
if let Some(matches) = app_matches.subcommand_matches("inspect") {
|
||||
if let Some(matches) = app_matches.subcommand_matches("eval") {
|
||||
inspect_command(matches, &import_paths, cache, ®istry, strict);
|
||||
} else if let Some(matches) = app_matches.subcommand_matches("build") {
|
||||
build_command(matches, &import_paths, cache, ®istry, strict);
|
||||
|
Loading…
x
Reference in New Issue
Block a user