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.
|
||||
- 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.
|
||||
- `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;
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args = Args::parse();
|
||||
match run(Args::parse()) {
|
||||
Ok(exit_code) => exit_code,
|
||||
Err(error) => {
|
||||
eprintln!("{error}");
|
||||
ExitCode::from(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let debug = args.debug;
|
||||
let files = match collect_files(args) {
|
||||
Ok(files) => files,
|
||||
Err(error) => {
|
||||
eprintln!("{error}");
|
||||
return ExitCode::from(2);
|
||||
fn run(args: Args) -> status::Result<ExitCode> {
|
||||
let files = collect_files(args.paths)?;
|
||||
if args.debug {
|
||||
dump_parsed_files(files)
|
||||
} else {
|
||||
check(files)
|
||||
}
|
||||
};
|
||||
if debug {
|
||||
}
|
||||
|
||||
fn dump_parsed_files(files: Vec<SourceFile>) -> status::Result<ExitCode> {
|
||||
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() {
|
||||
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
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
match xatu::future_sight(files) {
|
||||
Ok(report) if report.is_clean() => {
|
||||
fn check(files: Vec<SourceFile>) -> status::Result<ExitCode> {
|
||||
let report = xatu::future_sight(files)?;
|
||||
if report.is_clean() {
|
||||
println!("No findings.");
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Ok(report) => {
|
||||
Ok(ExitCode::SUCCESS)
|
||||
} else {
|
||||
print!("{report}");
|
||||
ExitCode::from(1)
|
||||
}
|
||||
Err(error) => {
|
||||
eprintln!("{error}");
|
||||
ExitCode::from(2)
|
||||
}
|
||||
Ok(ExitCode::from(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,21 +57,12 @@ struct Args {
|
||||
paths: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
fn collect_files(args: Args) -> status::Result<Vec<SourceFile>> {
|
||||
let paths: Vec<PathBuf> = args
|
||||
.paths
|
||||
.into_iter()
|
||||
.map(monorepo::workspace::resolve_workspace_path)
|
||||
.collect();
|
||||
|
||||
let files: Vec<SourceFile> = paths
|
||||
.iter()
|
||||
.map(|path| collect_source_files(path))
|
||||
.collect::<status::Result<Vec<_>>>()?
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
fn collect_files(paths: Vec<PathBuf>) -> status::Result<Vec<SourceFile>> {
|
||||
let mut files = Vec::new();
|
||||
for path in paths {
|
||||
let path = monorepo::workspace::resolve_workspace_path(path);
|
||||
files.extend(collect_source_files(&path)?);
|
||||
}
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user