Improve CLI; fix Ruby integration
This commit is contained in:
parent
ae0740d9c4
commit
9b2a348fd4
|
@ -31,7 +31,7 @@ Precompiled binaries are available for x86-64 Linux, macOS, and Windows.
|
|||
Use the `--help` argument for more details.
|
||||
|
||||
```bash
|
||||
minify-html --src /path/to/src.html --out /path/to/output.min.html
|
||||
minify-html --src /path/to/src.html --out /path/to/output.min.html --css --js
|
||||
```
|
||||
|
||||
### API
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[package]
|
||||
publish = false
|
||||
name = "minify-html-cli"
|
||||
description = "Extremely fast and smart HTML + JS + CSS minifier"
|
||||
version = "0.4.0"
|
||||
authors = ["Wilson Lin <code@wilsonl.in>"]
|
||||
edition = "2018"
|
||||
|
|
|
@ -6,13 +6,18 @@ use structopt::StructOpt;
|
|||
use minify_html::{Cfg, FriendlyError, with_friendly_error};
|
||||
|
||||
#[derive(StructOpt)]
|
||||
#[structopt(name = "minify-html", about = "Extremely fast and smart HTML + JS + CSS minifier")]
|
||||
struct Cli {
|
||||
/// File to minify; omit for stdin.
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
src: Option<std::path::PathBuf>,
|
||||
/// Output destination; omit for stdout.
|
||||
#[structopt(short, long, parse(from_os_str))]
|
||||
out: Option<std::path::PathBuf>,
|
||||
/// Enables JS minification.
|
||||
#[structopt(long)]
|
||||
js: bool,
|
||||
/// Enables CSS minification.
|
||||
#[structopt(long)]
|
||||
css: bool,
|
||||
}
|
||||
|
|
|
@ -15,14 +15,18 @@ methods! {
|
|||
.to_string()
|
||||
.into_bytes();
|
||||
|
||||
let cfg_hash = cfg_hash
|
||||
.map_err(|e| VM::raise_ex(e) )
|
||||
.unwrap();
|
||||
|
||||
let cfg = &Cfg {
|
||||
minify_js: cfg_hash
|
||||
.map(|h| h.at(&Symbol::new("minify_js")))
|
||||
.and_then(|e| e.try_convert_to::<Boolean>())
|
||||
.at(&Symbol::new("minify_js"))
|
||||
.try_convert_to::<Boolean>()
|
||||
.map_or(false, |v| v.to_bool()),
|
||||
minify_css: cfg_hash
|
||||
.map(|h| h.at(&Symbol::new("minify_css")))
|
||||
.and_then(|e| e.try_convert_to::<Boolean>())
|
||||
.at(&Symbol::new("minify_css"))
|
||||
.try_convert_to::<Boolean>()
|
||||
.map_or(false, |v| v.to_bool()),
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue