mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
Make the out flag optional
This commit is contained in:
parent
b31e95567d
commit
267b575e8b
15
src/main.rs
15
src/main.rs
@ -33,7 +33,7 @@ fn do_flags<'a>() -> clap::ArgMatches<'a> {
|
|||||||
(about: "Universal Configuration Grammar compiler.")
|
(about: "Universal Configuration Grammar compiler.")
|
||||||
(@subcommand build =>
|
(@subcommand build =>
|
||||||
(about: "Compile a specific ucg file.")
|
(about: "Compile a specific ucg file.")
|
||||||
(@arg sym: --sym +takes_value "Specify a specific let binding in the ucg file to output.")
|
(@arg sym: --sym +takes_value +required "Specify a specific let binding in the ucg file to output.")
|
||||||
(@arg target: --target -t +required +takes_value "Target output type. (flags, json, env)")
|
(@arg target: --target -t +required +takes_value "Target output type. (flags, json, env)")
|
||||||
(@arg out: --out -o +takes_value "Output file to write to.")
|
(@arg out: --out -o +takes_value "Output file to write to.")
|
||||||
(@arg INPUT: +required "Input ucg file to build.")
|
(@arg INPUT: +required "Input ucg file to build.")
|
||||||
@ -45,9 +45,12 @@ fn do_flags<'a>() -> clap::ArgMatches<'a> {
|
|||||||
).get_matches()
|
).get_matches()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_converter(c: ConverterRunner, v: Rc<Val>, f: &str) -> io::Result<()> {
|
fn run_converter(c: ConverterRunner, v: Rc<Val>, f: Option<&str>) -> io::Result<()> {
|
||||||
let file = File::create(f);
|
let file: Box<std::io::Write> = match f {
|
||||||
c.convert(v, Box::new(file.unwrap()))
|
Some(f) => Box::new(try!(File::create(f))),
|
||||||
|
None => Box::new(io::stdout()),
|
||||||
|
};
|
||||||
|
c.convert(v, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -55,7 +58,7 @@ fn main() {
|
|||||||
let app = do_flags();
|
let app = do_flags();
|
||||||
if let Some(matches) = app.subcommand_matches("build") {
|
if let Some(matches) = app.subcommand_matches("build") {
|
||||||
let file = matches.value_of("INPUT").unwrap();
|
let file = matches.value_of("INPUT").unwrap();
|
||||||
let out = matches.value_of("out").unwrap();
|
let out = matches.value_of("out");
|
||||||
let sym = matches.value_of("sym");
|
let sym = matches.value_of("sym");
|
||||||
let target = matches.value_of("target").unwrap();
|
let target = matches.value_of("target").unwrap();
|
||||||
let mut builder = build::Builder::new();
|
let mut builder = build::Builder::new();
|
||||||
@ -73,7 +76,7 @@ fn main() {
|
|||||||
match val {
|
match val {
|
||||||
Some(value) => {
|
Some(value) => {
|
||||||
run_converter(converter, value, out).unwrap();
|
run_converter(converter, value, out).unwrap();
|
||||||
println!("Build successful");
|
eprintln!("Build successful");
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user