add all commandline flags/args from dart-sass
This commit is contained in:
parent
daf7f247cf
commit
1326e8f000
155
src/main.rs
155
src/main.rs
@ -1,21 +1,38 @@
|
|||||||
|
use std::fs::File;
|
||||||
use std::io::{stdout, BufWriter, Write};
|
use std::io::{stdout, BufWriter, Write};
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{arg_enum, App, Arg};
|
||||||
|
|
||||||
use grass::StyleSheet;
|
use grass::StyleSheet;
|
||||||
|
|
||||||
fn main() {
|
arg_enum! {
|
||||||
|
#[derive(PartialEq, Debug)]
|
||||||
|
pub enum Style {
|
||||||
|
Expanded,
|
||||||
|
Compressed,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arg_enum! {
|
||||||
|
#[derive(PartialEq, Debug)]
|
||||||
|
pub enum SourceMapUrls {
|
||||||
|
Relative,
|
||||||
|
Absolute,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> std::io::Result<()> {
|
||||||
let matches = App::new("grass")
|
let matches = App::new("grass")
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
.about("SCSS Compiler in rust")
|
.about("SCSS Compiler in rust")
|
||||||
.version_short("v")
|
.version_short("v")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("stdin")
|
Arg::with_name("STDIN")
|
||||||
.long("stdin")
|
.long("stdin")
|
||||||
.help("Read the stylesheet from stdin"),
|
.help("Read the stylesheet from stdin"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("indented")
|
Arg::with_name("INDENTED")
|
||||||
.long("indented")
|
.long("indented")
|
||||||
.help("Use the indented syntax for input from stdin"),
|
.help("Use the indented syntax for input from stdin"),
|
||||||
)
|
)
|
||||||
@ -23,57 +40,133 @@ fn main() {
|
|||||||
Arg::with_name("LOAD_PATH")
|
Arg::with_name("LOAD_PATH")
|
||||||
.short("I")
|
.short("I")
|
||||||
.long("load-path")
|
.long("load-path")
|
||||||
.help("A path to use when resolving imports")
|
.help("A path to use when resolving imports. May be passed multiple times.")
|
||||||
|
.multiple(true)
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("style")
|
Arg::with_name("STYLE")
|
||||||
// dart sass uses -s
|
|
||||||
.short("s")
|
.short("s")
|
||||||
// ruby sass uses -t
|
|
||||||
.short("t")
|
|
||||||
.long("style")
|
.long("style")
|
||||||
.help("Expanded (default) or compressed output")
|
.help("Minified or expanded output")
|
||||||
|
.default_value("expanded")
|
||||||
|
.case_insensitive(true)
|
||||||
|
.possible_values(&Style::variants())
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("update")
|
Arg::with_name("NO_CHARSET")
|
||||||
|
.long("no-charset")
|
||||||
|
.help("Don't emit a @charset or BOM for CSS with non-ASCII characters."),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("UPDATE")
|
||||||
.long("update")
|
.long("update")
|
||||||
.help("Only compile out-of-date stylesheets"),
|
.help("Only compile out-of-date stylesheets."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("precision")
|
Arg::with_name("NO_ERROR_CSS")
|
||||||
.long("precision")
|
.long("no-error-css")
|
||||||
.help("Number of digits to emit for floats")
|
.help("When an error occurs, don't emit a stylesheet describing it."),
|
||||||
|
)
|
||||||
|
// Source maps
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("NO_SOURCE_MAP")
|
||||||
|
.long("no-source-map")
|
||||||
|
.help("Whether to generate source maps."),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("SOURCE_MAP_URLS")
|
||||||
|
.long("source-map-urls")
|
||||||
|
.help("How to link from source maps to source files.")
|
||||||
|
.default_value("relative")
|
||||||
|
.case_insensitive(true)
|
||||||
|
.possible_values(&SourceMapUrls::variants())
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("quiet")
|
Arg::with_name("EMBED_SOURCES")
|
||||||
|
.long("embed-sources")
|
||||||
|
.help("Embed source file contents in source maps."),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("EMBED_SOURCE_MAP")
|
||||||
|
.long("embed-source-map")
|
||||||
|
.help("Embed source map contents in CSS."),
|
||||||
|
)
|
||||||
|
// Other
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("WATCH")
|
||||||
|
.long("watch")
|
||||||
|
.help("Watch stylesheets and recompile when they change."),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("POLL")
|
||||||
|
.long("poll")
|
||||||
|
.help("Manually check for changes rather than using a native watcher. Only valid with --watch.")
|
||||||
|
.requires("WATCH"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("NO_STOP_ON_ERROR")
|
||||||
|
.long("no-stop-on-error")
|
||||||
|
.help("Continue to compile more files after error is encountered.")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("INTERACTIVE")
|
||||||
|
.short("i")
|
||||||
|
.long("interactive")
|
||||||
|
.help("Run an interactive SassScript shell.")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("NO_COLOR")
|
||||||
|
.short("c")
|
||||||
|
.long("no-color")
|
||||||
|
.help("Whether to use terminal colors for messages.")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("NO_UNICODE")
|
||||||
|
.long("no-unicode")
|
||||||
|
.help("Whether to use Unicode characters for messages.")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("QUIET")
|
||||||
.short("q")
|
.short("q")
|
||||||
.long("quiet")
|
.long("quiet")
|
||||||
.help("Number of digits to emit for floats"),
|
.help("Don't print warnings."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("INPUT")
|
Arg::with_name("INPUT")
|
||||||
.required(true)
|
.required(true)
|
||||||
.multiple(true)
|
|
||||||
.help("SCSS files"),
|
.help("SCSS files"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("OUTPUT")
|
||||||
|
.help("Output SCSS file")
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let mut stdout = BufWriter::new(stdout());
|
if let Some(name) = matches.value_of("INPUT") {
|
||||||
if let Some(inputs) = matches.values_of("INPUT") {
|
if let Some(path) = matches.value_of("OUTPUT") {
|
||||||
for name in inputs {
|
let mut buf = BufWriter::new(File::open(path).unwrap_or(File::create(path)?));
|
||||||
stdout
|
buf.write_all(
|
||||||
.write_all(
|
StyleSheet::from_path(name)
|
||||||
StyleSheet::from_path(&name)
|
.unwrap_or_else(|e| {
|
||||||
.unwrap_or_else(|e| {
|
eprintln!("{}", e);
|
||||||
eprintln!("{}", e);
|
std::process::exit(1)
|
||||||
std::process::exit(1)
|
})
|
||||||
})
|
.as_bytes(),
|
||||||
.as_bytes(),
|
)?;
|
||||||
)
|
} else {
|
||||||
.unwrap();
|
let mut stdout = BufWriter::new(stdout());
|
||||||
|
stdout.write_all(
|
||||||
|
StyleSheet::from_path(name)
|
||||||
|
.unwrap_or_else(|e| {
|
||||||
|
eprintln!("{}", e);
|
||||||
|
std::process::exit(1)
|
||||||
|
})
|
||||||
|
.as_bytes(),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user