Added an --out-name param to the CLI, to allow custom output file names

This commit is contained in:
DavidOConnor
2018-12-04 21:35:05 -05:00
parent 5665a0e6c0
commit a4bc5049c6
2 changed files with 16 additions and 1 deletions

View File

@ -27,6 +27,7 @@ mod wasm_utils;
pub struct Bindgen {
input: Input,
out_name: Option<String>,
nodejs: bool,
nodejs_experimental_modules: bool,
browser: bool,
@ -56,6 +57,7 @@ impl Bindgen {
pub fn new() -> Bindgen {
Bindgen {
input: Input::None,
out_name: None,
nodejs: false,
nodejs_experimental_modules: false,
browser: false,
@ -77,6 +79,11 @@ impl Bindgen {
self
}
pub fn out_name(&mut self, name: &str) -> &mut Bindgen {
self.out_name = Some(name.to_string());
self
}
/// Explicitly specify the already parsed input module.
pub fn input_module(&mut self, name: &str, module: Module) -> &mut Bindgen {
let name = name.to_string();
@ -155,7 +162,10 @@ impl Bindgen {
.with_context(|_| format!("failed to read `{}`", path.display()))?;
let module = parity_wasm::deserialize_buffer::<Module>(&contents)
.context("failed to parse input file as wasm")?;
let stem = path.file_stem().unwrap().to_str().unwrap();
let stem = match &self.out_name {
Some(name) => &name,
None => path.file_stem().unwrap().to_str().unwrap(),
};
(module, stem)
}
};