chore(xatu): merge debug CLI refactor into scope graph branch
This commit is contained in:
@@ -124,3 +124,5 @@
|
|||||||
Copy Nix fixtures into `TEST_TMPDIR` before passing their paths to CLI tests.
|
Copy Nix fixtures into `TEST_TMPDIR` before passing their paths to CLI tests.
|
||||||
- The vendored `rustversion-1.0.23/build/` files are currently ignored and untracked.
|
- The vendored `rustversion-1.0.23/build/` files are currently ignored and untracked.
|
||||||
Fresh worktrees cannot build Xatu tests until those upstream files are restored.
|
Fresh worktrees cannot build Xatu tests until those upstream files are restored.
|
||||||
|
- `status::ResultExt` requires errors that implement `Into<Status>`, not arbitrary `std::error::Error` values.
|
||||||
|
Map other errors explicitly with a status code and `with_source`.
|
||||||
|
|||||||
@@ -5,45 +5,46 @@ use std::process::ExitCode;
|
|||||||
use xatu::SourceFile;
|
use xatu::SourceFile;
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let args = Args::parse();
|
match run(Args::parse()) {
|
||||||
|
Ok(exit_code) => exit_code,
|
||||||
let debug = args.debug;
|
|
||||||
let files = match collect_files(args) {
|
|
||||||
Ok(files) => files,
|
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
eprintln!("{error}");
|
eprintln!("{error}");
|
||||||
return ExitCode::from(2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if debug {
|
|
||||||
let report = xatu::debug(files);
|
|
||||||
match serde_json::to_string_pretty(&report) {
|
|
||||||
Ok(json) => println!("{json}"),
|
|
||||||
Err(error) => {
|
|
||||||
eprintln!("{error}");
|
|
||||||
return ExitCode::from(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return if report.has_parse_errors() {
|
|
||||||
ExitCode::from(2)
|
ExitCode::from(2)
|
||||||
} else {
|
}
|
||||||
ExitCode::SUCCESS
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match xatu::future_sight(files) {
|
fn run(args: Args) -> status::Result<ExitCode> {
|
||||||
Ok(report) if report.is_clean() => {
|
let files = collect_files(args.paths)?;
|
||||||
println!("No findings.");
|
if args.debug {
|
||||||
ExitCode::SUCCESS
|
dump_parsed_files(files)
|
||||||
}
|
} else {
|
||||||
Ok(report) => {
|
check(files)
|
||||||
print!("{report}");
|
}
|
||||||
ExitCode::from(1)
|
}
|
||||||
}
|
|
||||||
Err(error) => {
|
fn dump_parsed_files(files: Vec<SourceFile>) -> status::Result<ExitCode> {
|
||||||
eprintln!("{error}");
|
let report = xatu::debug(files);
|
||||||
ExitCode::from(2)
|
let json = serde_json::to_string_pretty(&report).map_err(|error| {
|
||||||
}
|
status::Status::internal("failed to serialize parser output").with_source(error)
|
||||||
|
})?;
|
||||||
|
println!("{json}");
|
||||||
|
|
||||||
|
Ok(if report.has_parse_errors() {
|
||||||
|
ExitCode::from(2)
|
||||||
|
} else {
|
||||||
|
ExitCode::SUCCESS
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check(files: Vec<SourceFile>) -> status::Result<ExitCode> {
|
||||||
|
let report = xatu::future_sight(files)?;
|
||||||
|
if report.is_clean() {
|
||||||
|
println!("No findings.");
|
||||||
|
Ok(ExitCode::SUCCESS)
|
||||||
|
} else {
|
||||||
|
print!("{report}");
|
||||||
|
Ok(ExitCode::from(1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,21 +57,12 @@ struct Args {
|
|||||||
paths: Vec<PathBuf>,
|
paths: Vec<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_files(args: Args) -> status::Result<Vec<SourceFile>> {
|
fn collect_files(paths: Vec<PathBuf>) -> status::Result<Vec<SourceFile>> {
|
||||||
let paths: Vec<PathBuf> = args
|
let mut files = Vec::new();
|
||||||
.paths
|
for path in paths {
|
||||||
.into_iter()
|
let path = monorepo::workspace::resolve_workspace_path(path);
|
||||||
.map(monorepo::workspace::resolve_workspace_path)
|
files.extend(collect_source_files(&path)?);
|
||||||
.collect();
|
}
|
||||||
|
|
||||||
let files: Vec<SourceFile> = paths
|
|
||||||
.iter()
|
|
||||||
.map(|path| collect_source_files(path))
|
|
||||||
.collect::<status::Result<Vec<_>>>()?
|
|
||||||
.into_iter()
|
|
||||||
.flatten()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(files)
|
Ok(files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user