@@ -6,7 +6,7 @@ use std::{
|
||||
|
||||
use decodal::{
|
||||
Data, Diagnostic, DiagnosticKind, Engine, LoadedSource, SourceId, SourceLoader, Span,
|
||||
format_diagnostic_with, format_source_with_source_id,
|
||||
format_diagnostic_with,
|
||||
};
|
||||
|
||||
fn main() -> ExitCode {
|
||||
@@ -38,17 +38,6 @@ fn run() -> Result<(), String> {
|
||||
println!("ok");
|
||||
Ok(())
|
||||
}
|
||||
"fmt" | "format" => {
|
||||
let next = args.next().unwrap_or_else(|| String::from("-"));
|
||||
if next == "--write" || next == "-w" {
|
||||
let path = args
|
||||
.next()
|
||||
.ok_or_else(|| String::from("missing file path for `decodal fmt --write`"))?;
|
||||
format_path(&path, true)
|
||||
} else {
|
||||
format_path(&next, false)
|
||||
}
|
||||
}
|
||||
"eval" | "materialize" => {
|
||||
let path = args.next().unwrap_or_else(|| String::from("-"));
|
||||
let data = materialize_path(&path)?;
|
||||
@@ -65,21 +54,6 @@ fn run() -> Result<(), String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn format_path(path: &str, write: bool) -> Result<(), String> {
|
||||
if write && path == "-" {
|
||||
return Err(String::from("cannot use --write with stdin"));
|
||||
}
|
||||
let root = read_root_source(path).map_err(format_raw_diagnostic)?;
|
||||
let formatted = format_source_with_source_id(SourceId(0), &root.source)
|
||||
.map_err(|error| format_diagnostic_with_root(&error, &root.name))?;
|
||||
if write {
|
||||
fs::write(path, formatted).map_err(|error| format!("failed to write `{path}`: {error}"))?;
|
||||
} else {
|
||||
print!("{formatted}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn materialize_path(path: &str) -> Result<Data, String> {
|
||||
let root = read_root_source(path).map_err(format_raw_diagnostic)?;
|
||||
let root_name = root.name.clone();
|
||||
@@ -169,11 +143,10 @@ fn print_help() {
|
||||
println!("Decodal - Deferred Constraint Data Language");
|
||||
println!();
|
||||
println!("Usage:");
|
||||
println!(" decodal <file.dcdl> Materialize a DCDL file");
|
||||
println!(" decodal eval <file.dcdl> Materialize a DCDL file");
|
||||
println!(" decodal check <file.dcdl> Evaluate and materialize without printing data");
|
||||
println!(" decodal fmt [--write] <file.dcdl> Format a DCDL file");
|
||||
println!(" decodal - Read DCDL source from stdin");
|
||||
println!(" decodal <file.dcdl> Materialize a DCDL file");
|
||||
println!(" decodal eval <file.dcdl> Materialize a DCDL file");
|
||||
println!(" decodal check <file.dcdl> Evaluate and materialize without printing data");
|
||||
println!(" decodal - Read DCDL source from stdin");
|
||||
}
|
||||
|
||||
fn format_diagnostic_with_root(error: &Diagnostic, root_name: &str) -> String {
|
||||
|
||||
Reference in New Issue
Block a user