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.
|
Universal Configuration Grammar compiler.
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
ucg [SUBCOMMAND]
|
ucg [FLAGS] [SUBCOMMAND]
|
||||||
|
|
||||||
FLAGS:
|
FLAGS:
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
-V, --version Prints version information
|
--no-strict Turn off strict checking.
|
||||||
|
-V, --version Prints version information
|
||||||
|
|
||||||
SUBCOMMANDS:
|
SUBCOMMANDS:
|
||||||
build Build a specific ucg file.
|
build Build a list of ucg files.
|
||||||
help Prints this message or the help of the given subcommand(s)
|
converters list the available converters
|
||||||
inspect Inspect a specific symbol in a ucg file.
|
env Describe the environment variables ucg uses.
|
||||||
test Check a specific ucg file for errors.
|
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
|
## 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!())
|
(author: crate_authors!())
|
||||||
(about: "Universal Configuration Grammar compiler.")
|
(about: "Universal Configuration Grammar compiler.")
|
||||||
(@arg nostrict: --("no-strict") "Turn off strict checking.")
|
(@arg nostrict: --("no-strict") "Turn off strict checking.")
|
||||||
(@subcommand inspect =>
|
(@subcommand eval =>
|
||||||
(about: "Inspect a specific symbol in a ucg file.")
|
(about: "Evaluate an expression with an optional ucg file as context.")
|
||||||
(@arg expr: --expr +takes_value +required "Specify a specific binding in the ucg file to output.")
|
(@arg expr: --expr -e +takes_value +required "Expression to evaluate.")
|
||||||
(@arg target: --format +required +takes_value "Inspect output type. (flags, json, env, exec)")
|
(@arg target: --format +takes_value "Output type. (flags, json, env, exec) defaults to json.")
|
||||||
(@arg INPUT: +required "Input ucg file to inspect symbol from.")
|
(@arg INPUT: "ucg file to use as context for the expression.")
|
||||||
)
|
)
|
||||||
(@subcommand build =>
|
(@subcommand build =>
|
||||||
(about: "Build a list of ucg files.")
|
(about: "Build a list of ucg files.")
|
||||||
@ -244,9 +244,9 @@ fn inspect_command(
|
|||||||
registry: &ConverterRegistry,
|
registry: &ConverterRegistry,
|
||||||
strict: bool,
|
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 sym = matches.value_of("expr");
|
||||||
let target = matches.value_of("target").unwrap();
|
let target = matches.value_of("target").unwrap_or("json");
|
||||||
let mut builder =
|
let mut builder =
|
||||||
build::FileBuilder::new(std::env::current_dir().unwrap(), import_paths, cache);
|
build::FileBuilder::new(std::env::current_dir().unwrap(), import_paths, cache);
|
||||||
builder.set_strict(strict);
|
builder.set_strict(strict);
|
||||||
@ -282,17 +282,20 @@ fn inspect_command(
|
|||||||
Some(value) => {
|
Some(value) => {
|
||||||
// We use None here because we always output to stdout for an inspect.
|
// We use None here because we always output to stdout for an inspect.
|
||||||
run_converter(converter, value, None).unwrap();
|
run_converter(converter, value, None).unwrap();
|
||||||
eprintln!("Build successful");
|
println!("");
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
eprintln!("Build results in no value.");
|
eprintln!("No value.");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
eprintln!("No such converter {}", target);
|
eprintln!(
|
||||||
|
"No such format {}\nrun `ucg converters` to see available formats.",
|
||||||
|
target
|
||||||
|
);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -448,7 +451,7 @@ fn main() {
|
|||||||
} else {
|
} else {
|
||||||
true
|
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);
|
inspect_command(matches, &import_paths, cache, ®istry, strict);
|
||||||
} else if let Some(matches) = app_matches.subcommand_matches("build") {
|
} else if let Some(matches) = app_matches.subcommand_matches("build") {
|
||||||
build_command(matches, &import_paths, cache, ®istry, strict);
|
build_command(matches, &import_paths, cache, ®istry, strict);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user