Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ shell-words = "1.1.0"
subst = "0.3.8"
path-slash = "0.2.1"
jobslot = "0.2.23"
ptree = { version = "0.5.2", default-features = false }

[profile.release]
lto = "fat"
Expand Down
14 changes: 14 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ pub fn clap() -> clap::Command {
.arg(define())
.add(SubcommandCandidates::new(task_completer)),
)
.subcommand(
Command::new("inspect")
.about("inspect current configuration")
.arg(build_dir())
.subcommand(
Command::new("builders").arg(
Arg::new("tree")
.short('t')
.long("tree")
.help("output a tree of the configuration builders")
.action(ArgAction::SetTrue),
),
),
)
.subcommand(
Command::new("clean")
.about("clean current configuration")
Expand Down
43 changes: 43 additions & 0 deletions src/inspect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Inspect Laze project files, without any build output

use std::io::Write;

use anyhow::Result;
use camino::Utf8PathBuf;
use ptree::{write_tree, TreeBuilder};

use crate::{data::load, Context, ContextBag};

pub(crate) struct BuildInspector {
contexts: ContextBag,
}

impl BuildInspector {
pub(crate) fn from_project(project_file: Utf8PathBuf, build_dir: Utf8PathBuf) -> Result<Self> {
let (contexts, _, _) = load(&project_file, &build_dir)?;
Ok(Self { contexts })
}
pub(crate) fn inspect_builders(&self) -> Vec<&Context> {
self.contexts.builders_vec()
}

fn add_tree_element(&self, context: &Context, tree: &mut TreeBuilder) {
self.contexts
.contexts
.iter()
.filter(|c| Some(context) == c.get_parent(&self.contexts))
.for_each(|c| {
tree.begin_child(c.name.to_string());
self.add_tree_element(c, tree);
tree.end_child();
})
}
Comment on lines +24 to +34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a blunt recursive iteration over all contexts. I don't know whether it is sufficiently performant.


pub(crate) fn write_tree<W: Write>(&self, w: W) -> Result<()> {
let default = self.contexts.get_by_name(&"default".to_string()).unwrap();
let mut tree_builder = TreeBuilder::new("default".to_string()); // The first node is always called default
self.add_tree_element(default, &mut tree_builder);
let tree = tree_builder.build();
write_tree(&tree, w).map_err(|e| e.into())
}
}
Loading
Loading