fix some clap deprecation warnings
This commit is contained in:
parent
2958b92e82
commit
95d09192cd
@ -4,188 +4,210 @@ use std::{
|
|||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::{arg_enum, App, AppSettings, Arg};
|
use clap::{value_parser, Arg, ArgEnum, Command, PossibleValue};
|
||||||
|
|
||||||
use grass::{from_path, from_string, Options, OutputStyle};
|
use grass::{from_path, from_string, Options, OutputStyle};
|
||||||
|
|
||||||
arg_enum! {
|
#[derive(Eq, PartialEq, Debug, Clone, Copy)]
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
|
||||||
pub enum Style {
|
pub enum Style {
|
||||||
Expanded,
|
Expanded,
|
||||||
Compressed,
|
Compressed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ArgEnum for Style {
|
||||||
|
fn value_variants<'a>() -> &'a [Self] {
|
||||||
|
&[Self::Expanded, Self::Compressed]
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_enum! {
|
fn to_possible_value<'a>(&self) -> Option<PossibleValue<'a>> {
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
Some(match self {
|
||||||
|
Self::Expanded => PossibleValue::new("expanded"),
|
||||||
|
Self::Compressed => PossibleValue::new("compressed"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Eq, PartialEq, Debug, Clone)]
|
||||||
pub enum SourceMapUrls {
|
pub enum SourceMapUrls {
|
||||||
Relative,
|
Relative,
|
||||||
Absolute,
|
Absolute,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ArgEnum for SourceMapUrls {
|
||||||
|
fn value_variants<'a>() -> &'a [Self] {
|
||||||
|
&[Self::Relative, Self::Absolute]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_possible_value<'a>(&self) -> Option<PossibleValue<'a>> {
|
||||||
|
Some(match self {
|
||||||
|
Self::Relative => PossibleValue::new("relative"),
|
||||||
|
Self::Absolute => PossibleValue::new("absolute"),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let matches = App::new("grass")
|
let matches = Command::new("grass")
|
||||||
.setting(AppSettings::ColoredHelp)
|
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
.about("A near-feature-complete Sass compiler written purely in Rust")
|
.about("A near-feature-complete Sass compiler written purely in Rust")
|
||||||
.version_short('v')
|
.mut_arg("version", |arg| arg.short('v'))
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("STDIN")
|
Arg::new("STDIN")
|
||||||
.long("stdin")
|
.long("stdin")
|
||||||
.help("Read the stylesheet from stdin"),
|
.help("Read the stylesheet from stdin"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("INDENTED")
|
Arg::new("INDENTED")
|
||||||
.long("indented")
|
.long("indented")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Use the indented syntax for input from stdin"),
|
.help("Use the indented syntax for input from stdin"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("LOAD_PATH")
|
Arg::new("LOAD_PATH")
|
||||||
.short('I')
|
.short('I')
|
||||||
.long("load-path")
|
.long("load-path")
|
||||||
.help("A path to use when resolving imports. May be passed multiple times.")
|
.help("A path to use when resolving imports. May be passed multiple times.")
|
||||||
.multiple(true)
|
.multiple_occurrences(true)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
.value_parser(value_parser!(String))
|
||||||
.number_of_values(1)
|
.number_of_values(1)
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("STYLE")
|
Arg::new("STYLE")
|
||||||
// this is required for compatibility with ruby sass
|
// this is required for compatibility with ruby sass
|
||||||
.short_alias('t')
|
.short_alias('t')
|
||||||
.short('s')
|
.short('s')
|
||||||
.long("style")
|
.long("style")
|
||||||
.help("Minified or expanded output")
|
.help("Minified or expanded output")
|
||||||
.default_value("expanded")
|
.default_value("expanded")
|
||||||
.case_insensitive(true)
|
.ignore_case(true)
|
||||||
.possible_values(&Style::variants())
|
.takes_value(true)
|
||||||
.takes_value(true),
|
.value_parser(value_parser!(Style)),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("NO_CHARSET")
|
Arg::new("NO_CHARSET")
|
||||||
.long("no-charset")
|
.long("no-charset")
|
||||||
.help("Don't emit a @charset or BOM for CSS with non-ASCII characters."),
|
.help("Don't emit a @charset or BOM for CSS with non-ASCII characters."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("UPDATE")
|
Arg::new("UPDATE")
|
||||||
.long("update")
|
.long("update")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Only compile out-of-date stylesheets."),
|
.help("Only compile out-of-date stylesheets."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("NO_ERROR_CSS")
|
Arg::new("NO_ERROR_CSS")
|
||||||
.long("no-error-css")
|
.long("no-error-css")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("When an error occurs, don't emit a stylesheet describing it."),
|
.help("When an error occurs, don't emit a stylesheet describing it."),
|
||||||
)
|
)
|
||||||
// Source maps
|
// Source maps
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("NO_SOURCE_MAP")
|
Arg::new("NO_SOURCE_MAP")
|
||||||
.long("no-source-map")
|
.long("no-source-map")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Whether to generate source maps."),
|
.help("Whether to generate source maps."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("SOURCE_MAP_URLS")
|
Arg::new("SOURCE_MAP_URLS")
|
||||||
.long("source-map-urls")
|
.long("source-map-urls")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("How to link from source maps to source files.")
|
.help("How to link from source maps to source files.")
|
||||||
.default_value("relative")
|
.default_value("relative")
|
||||||
.case_insensitive(true)
|
.ignore_case(true)
|
||||||
.possible_values(&SourceMapUrls::variants())
|
.takes_value(true)
|
||||||
.takes_value(true),
|
.value_parser(value_parser!(SourceMapUrls)),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("EMBED_SOURCES")
|
Arg::new("EMBED_SOURCES")
|
||||||
.long("embed-sources")
|
.long("embed-sources")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Embed source file contents in source maps."),
|
.help("Embed source file contents in source maps."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("EMBED_SOURCE_MAP")
|
Arg::new("EMBED_SOURCE_MAP")
|
||||||
.long("embed-source-map")
|
.long("embed-source-map")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Embed source map contents in CSS."),
|
.help("Embed source map contents in CSS."),
|
||||||
)
|
)
|
||||||
// Other
|
// Other
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("WATCH")
|
Arg::new("WATCH")
|
||||||
.long("watch")
|
.long("watch")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Watch stylesheets and recompile when they change."),
|
.help("Watch stylesheets and recompile when they change."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("POLL")
|
Arg::new("POLL")
|
||||||
.long("poll")
|
.long("poll")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Manually check for changes rather than using a native watcher. Only valid with --watch.")
|
.help("Manually check for changes rather than using a native watcher. Only valid with --watch.")
|
||||||
.requires("WATCH"),
|
.requires("WATCH"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("NO_STOP_ON_ERROR")
|
Arg::new("NO_STOP_ON_ERROR")
|
||||||
.long("no-stop-on-error")
|
.long("no-stop-on-error")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Continue to compile more files after error is encountered.")
|
.help("Continue to compile more files after error is encountered.")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("INTERACTIVE")
|
Arg::new("INTERACTIVE")
|
||||||
.short('i')
|
.short('i')
|
||||||
.long("interactive")
|
.long("interactive")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Run an interactive SassScript shell.")
|
.help("Run an interactive SassScript shell.")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("NO_COLOR")
|
Arg::new("NO_COLOR")
|
||||||
.short('c')
|
.short('c')
|
||||||
.long("no-color")
|
.long("no-color")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Whether to use terminal colors for messages.")
|
.help("Whether to use terminal colors for messages.")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("VERBOSE")
|
Arg::new("VERBOSE")
|
||||||
.long("verbose")
|
.long("verbose")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.help("Print all deprecation warnings even when they're repetitive.")
|
.help("Print all deprecation warnings even when they're repetitive.")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("NO_UNICODE")
|
Arg::new("NO_UNICODE")
|
||||||
.long("no-unicode")
|
.long("no-unicode")
|
||||||
.help("Whether to use Unicode characters for messages.")
|
.help("Whether to use Unicode characters for messages.")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("QUIET")
|
Arg::new("QUIET")
|
||||||
.short('q')
|
.short('q')
|
||||||
.long("quiet")
|
.long("quiet")
|
||||||
.help("Don't print warnings."),
|
.help("Don't print warnings."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("INPUT")
|
Arg::new("INPUT")
|
||||||
.required_unless("STDIN")
|
.value_parser(value_parser!(String))
|
||||||
.help("SCSS files"),
|
.required_unless_present("STDIN")
|
||||||
|
.help("Sass files"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("OUTPUT")
|
Arg::new("OUTPUT")
|
||||||
.help("Output SCSS file")
|
.help("Output CSS file")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hidden, legacy arguments
|
// Hidden, legacy arguments
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("PRECISION")
|
Arg::new("PRECISION")
|
||||||
.long("precision")
|
.long("precision")
|
||||||
.hidden(true)
|
.hide(true)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let load_paths = matches
|
let load_paths = matches
|
||||||
.values_of("LOAD_PATH")
|
.get_many::<String>("LOAD_PATH")
|
||||||
.map_or_else(Vec::new, |vals| vals.map(Path::new).collect());
|
.map_or_else(Vec::new, |vals| vals.map(Path::new).collect());
|
||||||
|
|
||||||
let style = match &matches.value_of("STYLE").unwrap().to_lowercase() as &str {
|
let style = match &matches.get_one::<Style>("STYLE").unwrap() {
|
||||||
"expanded" => OutputStyle::Expanded,
|
Style::Expanded => OutputStyle::Expanded,
|
||||||
"compressed" => OutputStyle::Compressed,
|
Style::Compressed => OutputStyle::Compressed,
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let options = &Options::default()
|
let options = &Options::default()
|
||||||
@ -196,7 +218,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
.allows_charset(!matches.is_present("NO_CHARSET"));
|
.allows_charset(!matches.is_present("NO_CHARSET"));
|
||||||
|
|
||||||
let (mut stdout_write, mut file_write);
|
let (mut stdout_write, mut file_write);
|
||||||
let buf_out: &mut dyn Write = if let Some(path) = matches.value_of("OUTPUT") {
|
let buf_out: &mut dyn Write = if let Some(path) = matches.get_one::<&str>("OUTPUT") {
|
||||||
file_write = OpenOptions::new()
|
file_write = OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
@ -209,7 +231,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
buf_out.write_all(
|
buf_out.write_all(
|
||||||
if let Some(name) = matches.value_of("INPUT") {
|
if let Some(name) = matches.get_one::<String>("INPUT") {
|
||||||
from_path(name, options)
|
from_path(name, options)
|
||||||
} else if matches.is_present("STDIN") {
|
} else if matches.is_present("STDIN") {
|
||||||
from_string(
|
from_string(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user