Skip to content

Commit

Permalink
Allow hyphen for input/output of CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
konradkoschel committed Jul 11, 2024
1 parent de8431f commit 981686e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/cli/src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct JS {
}

impl JS {
fn from_string(source_code: String) -> JS {
pub fn from_string(source_code: String) -> JS {
JS {
source_code: Rc::new(source_code),
}
Expand Down
18 changes: 15 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use clap::Parser;
use js::JS;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::io::{Read, Write};
use wasm_generator::dynamic as dynamic_generator;

fn main() -> Result<()> {
Expand All @@ -21,7 +21,14 @@ fn main() -> Result<()> {
match args.command {
Command::EmitProvider(opts) => emit_provider(&opts),
Command::Compile(opts) => {
let js = JS::from_file(&opts.input)?;
let js = match opts.input.to_str() {
Some("-") => {
let mut content = String::new();
std::io::stdin().read_to_string(&mut content)?;
JS::from_string(content)
}
_ => JS::from_file(&opts.input)?,
};
let exports = match (&opts.wit, &opts.wit_world) {
(None, None) => Ok(vec![]),
(None, Some(_)) => Ok(vec![]),
Expand All @@ -33,7 +40,12 @@ fn main() -> Result<()> {
} else {
static_generator::generate(&js, exports, opts.no_source_compression)?
};
fs::write(&opts.output, wasm)?;
match opts.output.to_str() {
Some("-") => {
std::io::stdout().write_all(&wasm)?;
}
_ => fs::write(&opts.output, wasm)?,
}
Ok(())
}
}
Expand Down

0 comments on commit 981686e

Please sign in to comment.