Improve CLI

This commit is contained in:
Wilson Lin 2021-08-08 11:44:13 +10:00
parent b704f51940
commit a5263993a1
2 changed files with 6 additions and 6 deletions

View File

@ -42,7 +42,7 @@ Precompiled binaries are available for Linux, macOS, and Windows.
Use the `--help` argument for more details. Use the `--help` argument for more details.
```bash ```bash
minify-html --src /path/to/src.html --out /path/to/output.min.html --css --js minify-html --output /path/to/output.min.html --keep-closing-tags --minify-css /path/to/src.html
``` ```
</details> </details>

View File

@ -13,11 +13,11 @@ use minify_html::{minify, Cfg};
// WARNING: Keep descriptions in sync with Cfg. // WARNING: Keep descriptions in sync with Cfg.
struct Cli { struct Cli {
/// File to minify; omit for stdin. /// File to minify; omit for stdin.
#[structopt(short, long, parse(from_os_str))] #[structopt(parse(from_os_str))]
src: Option<std::path::PathBuf>, input: Option<std::path::PathBuf>,
/// Output destination; omit for stdout. /// Output destination; omit for stdout.
#[structopt(short, long, parse(from_os_str))] #[structopt(short, long, parse(from_os_str))]
out: Option<std::path::PathBuf>, output: Option<std::path::PathBuf>,
/// Minify JS in `<script>` tags that have a valid or no `type` attribute value. /// Minify JS in `<script>` tags that have a valid or no `type` attribute value.
#[structopt(long)] #[structopt(long)]
minify_js: bool, minify_js: bool,
@ -63,7 +63,7 @@ macro_rules! io_expect {
fn main() { fn main() {
let args = Cli::from_args(); let args = Cli::from_args();
let mut src_code = Vec::<u8>::new(); let mut src_code = Vec::<u8>::new();
let mut src_file: Box<dyn Read> = match args.src { let mut src_file: Box<dyn Read> = match args.input {
Some(p) => Box::new(io_expect!(File::open(p), "could not open source file")), Some(p) => Box::new(io_expect!(File::open(p), "could not open source file")),
None => Box::new(stdin()), None => Box::new(stdin()),
}; };
@ -85,7 +85,7 @@ fn main() {
remove_processing_instructions: args.remove_processing_instructions, remove_processing_instructions: args.remove_processing_instructions,
}, },
); );
let mut out_file: Box<dyn Write> = match args.out { let mut out_file: Box<dyn Write> = match args.output {
Some(p) => Box::new(io_expect!(File::create(p), "could not open output file")), Some(p) => Box::new(io_expect!(File::create(p), "could not open output file")),
None => Box::new(stdout()), None => Box::new(stdout()),
}; };