feat(xatu): scaffold source collection

This commit was merged in pull request #66.
This commit is contained in:
2026-09-17 14:09:47 -04:00
parent 87916a8e17
commit 7a3a3d6b90
6 changed files with 138 additions and 0 deletions

8
Cargo.lock generated
View File

@@ -251,6 +251,14 @@ dependencies = [
"windows-link",
]
[[package]]
name = "xatu"
version = "0.1.0"
dependencies = [
"clap",
"monorepo",
]
[[package]]
name = "zmij"
version = "1.0.23"

View File

@@ -3,6 +3,7 @@ members = [
"src/ariadne",
"src/machoke",
"src/monorepo",
"src/xatu",
]
resolver = "3"

18
src/xatu/BUILD Normal file
View File

@@ -0,0 +1,18 @@
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
rust_library(
name = "xatu_lib",
crate_name = "xatu",
srcs = ["xatu.rs"],
)
rust_binary(
name = "xatu",
crate_name = "xatu_cli",
srcs = ["xatu_main.rs"],
deps = [
":xatu_lib",
"//src/monorepo:monorepo",
"//third_party/crates:clap",
],
)

15
src/xatu/Cargo.toml Normal file
View File

@@ -0,0 +1,15 @@
[package]
name = "xatu"
version = "0.1.0"
edition = "2024"
[lib]
path = "xatu.rs"
[[bin]]
name = "xatu"
path = "xatu_main.rs"
[dependencies]
clap = { workspace = true, features = ["derive"] }
monorepo = { workspace = true }

16
src/xatu/xatu.rs Normal file
View File

@@ -0,0 +1,16 @@
use std::path::PathBuf;
pub fn run(files: Vec<SourceFile>) -> Result<()> {
for file in files {
println!("{}", file.path.display());
}
Ok(())
}
pub type Result<T> = std::result::Result<T, std::io::Error>;
#[derive(Debug)]
pub struct SourceFile {
pub path: PathBuf,
pub source: String,
}

80
src/xatu/xatu_main.rs Normal file
View File

@@ -0,0 +1,80 @@
use clap::Parser;
use std::path::{Path, PathBuf};
use xatu::SourceFile;
fn is_nix_file(path: &Path) -> bool {
path.extension().is_some_and(|extension| extension == "nix")
}
// TODO: Add configurable exclusions.
fn is_excluded_dir(path: &Path) -> bool {
path.file_name()
.and_then(|name| name.to_str())
.is_some_and(|name| {
matches!(
name,
".git"
| "bazel-bin"
| "bazel-dev"
| "bazel-out"
| "bazel-testlogs"
| "target"
| "third_party"
) || name == "result"
|| name.starts_with("result-")
})
}
fn collect_source_files(path: &Path) -> xatu::Result<Vec<SourceFile>> {
let metadata = std::fs::symlink_metadata(path)?;
if metadata.file_type().is_dir() {
if is_excluded_dir(path) {
return Ok(Vec::new());
}
let mut files = Vec::new();
for entry in std::fs::read_dir(path)? {
let entry = entry?;
files.extend(collect_source_files(&entry.path())?);
}
return Ok(files);
}
if metadata.file_type().is_file() && is_nix_file(path) {
return Ok(vec![SourceFile {
path: path.to_path_buf(),
source: std::fs::read_to_string(path)?,
}]);
}
Ok(Vec::new())
}
#[derive(Debug, Parser)]
struct Args {
#[arg(value_name = "PATH", default_value = ".")]
paths: Vec<PathBuf>,
}
fn main() -> xatu::Result<()> {
let args = Args::parse();
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::<xatu::Result<Vec<_>>>()?
.into_iter()
.flatten()
.collect();
xatu::run(files)
}