use clap::Parser;
use rsass::{
output::{Format, Style},
Error, FsFileContext, ScopeRef,
};
use std::io::{stdout, Write};
use std::path::PathBuf;
use std::process::exit;
fn main() {
match Args::parse().run() {
Ok(()) => (),
Err(err) => {
eprintln!("{}", err);
exit(1);
}
}
}
#[derive(Parser)]
#[clap(
about,
author,
version,
mut_arg("version", |v| v.short('v')),
after_help = "For information about rsass and its current state of \
development, please refer to https://github.com/kaj/rsass/ .\
\n\n\
The sass / scss languate itself is documented at \
https://sass-lang.com/ ."
)]
struct Args {
#[clap(long, default_value = "5")]
precision: usize,
#[clap(long, short = 't', ignore_case = true,
default_value = "expanded",
possible_values = Style::variants())]
style: Style,
#[cfg(feature = "unimplemented_args")]
#[clap(long)]
#[allow(unused)]
no_unicode: bool,
#[cfg(feature = "unimplemented_args")]
#[clap(long)]
#[allow(unused)]
no_color: bool,
#[cfg(feature = "unimplemented_args")]
#[clap(long)]
#[allow(unused)]
verbose: bool,
#[clap(long, short = 'I')]
load_path: Option<PathBuf>,
#[clap(required = true)]
input: Vec<PathBuf>,
}
impl Args {
fn run(self) -> Result<(), Error> {
let format = Format {
style: self.style,
precision: self.precision,
};
for name in &self.input {
let (mut file_context, source) = FsFileContext::for_path(name)?;
if let Some(include_path) = &self.load_path {
file_context.push_path(include_path.as_ref());
}
let source = source.parse()?;
let result = format.write_root(
source,
ScopeRef::new_global(format),
&file_context,
)?;
let out = stdout();
out.lock().write_all(&result)?;
}
Ok(())
}
}