diff options
author | Casey Rodarmor <casey@rodarmor.com> | 2024-01-18 11:25:38 -0800 |
---|---|---|
committer | Casey Rodarmor <casey@rodarmor.com> | 2024-01-18 11:25:38 -0800 |
commit | ea1bd6aa207f050b9a8d7a09d990fdb7630c83be (patch) | |
tree | 90f0f8148a47255fb1a227bea148ea5e81b21ecd | |
parent | 22d462bd5596eae8d0d5e9a6b9dd330e25255987 (diff) |
Start working on --tree
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | src/config.rs | 10 | ||||
-rw-r--r-- | src/subcommand.rs | 26 |
3 files changed, 39 insertions, 0 deletions
@@ -360,6 +360,9 @@ command-line interface. This does not, however, preclude fixing outright bugs, even if doing so might break `justfiles` that rely on their behavior. +Also, output of `just` which is human readable, such as error messages and the +output of `--list`, is not bound by the backwards compatibility guarantee. + There will never be a `just` 2.0. Any desirable backwards-incompatible changes will be opt-in on a per-`justfile` basis, so users may migrate at their leisure. diff --git a/src/config.rs b/src/config.rs index 0a071463..d1fbd132 100644 --- a/src/config.rs +++ b/src/config.rs @@ -56,6 +56,7 @@ mod cmd { pub(crate) const LIST: &str = "LIST"; pub(crate) const SHOW: &str = "SHOW"; pub(crate) const SUMMARY: &str = "SUMMARY"; + pub(crate) const TREE: &str = "TREE"; pub(crate) const VARIABLES: &str = "VARIABLES"; pub(crate) const ALL: &[&str] = &[ @@ -71,6 +72,7 @@ mod cmd { LIST, SHOW, SUMMARY, + TREE, VARIABLES, ]; @@ -84,6 +86,7 @@ mod cmd { LIST, SHOW, SUMMARY, + TREE, VARIABLES, ]; } @@ -382,6 +385,11 @@ impl Config { .help("List names of available recipes"), ) .arg( + Arg::with_name(cmd::TREE) + .long("tree") + .help("Show tree of available recipes"), + ) + .arg( Arg::with_name(cmd::VARIABLES) .long("variables") .help("List names of variables"), @@ -611,6 +619,8 @@ impl Config { variable: positional.arguments.into_iter().next(), overrides, } + } else if matches.is_present(cmd::TREE) { + Subcommand::Tree } else if matches.is_present(cmd::VARIABLES) { Subcommand::Variables } else { diff --git a/src/subcommand.rs b/src/subcommand.rs index 8dbcbaea..c90a90af 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -34,6 +34,7 @@ pub(crate) enum Subcommand { name: String, }, Summary, + Tree, Variables, } @@ -82,6 +83,7 @@ impl Subcommand { List => Self::list(config, 0, justfile), Show { ref name } => Self::show(config, name, justfile)?, Summary => Self::summary(config, justfile), + Tree => Self::tree(justfile), Variables => Self::variables(justfile), Changelog | Completions { .. } | Edit | Init | Run { .. } => unreachable!(), } @@ -569,6 +571,30 @@ impl Subcommand { } } + fn tree(justfile: &Justfile) { + for (i, (name, recipe)) in justfile.recipes.iter().enumerate() { + if recipe.is_public() { + if i == justfile.recipes.len() - 1 { + print!("└── "); + } else { + print!("├── "); + } + + println!("{name}"); + + for (i, dependency) in recipe.dependencies.iter().enumerate() { + if i == recipe.dependencies.len() - 1 { + print!("│ └── "); + } else { + print!("│ ├── "); + } + + println!("{}", dependency.recipe.name()); + } + } + } + } + fn variables(justfile: &Justfile) { for (i, (_, assignment)) in justfile.assignments.iter().enumerate() { if i > 0 { |