Skip to content
Merged
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
9 changes: 8 additions & 1 deletion src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ impl<'run, 'src> Analyzer<'run, 'src> {
loaded: &[PathBuf],
name: Option<Name<'src>>,
paths: &HashMap<PathBuf, PathBuf>,
private: bool,
root: &Path,
) -> RunResult<'src, Justfile<'src>> {
Self::default().justfile(asts, config, doc, groups, loaded, name, paths, root)
Self::default().justfile(
asts, config, doc, groups, loaded, name, paths, root, private,
)
}

fn justfile(
Expand All @@ -35,6 +38,7 @@ impl<'run, 'src> Analyzer<'run, 'src> {
name: Option<Name<'src>>,
paths: &HashMap<PathBuf, PathBuf>,
root: &Path,
private: bool,
) -> RunResult<'src, Justfile<'src>> {
let mut definitions = HashMap::new();
let mut imports = HashSet::new();
Expand Down Expand Up @@ -69,6 +73,7 @@ impl<'run, 'src> Analyzer<'run, 'src> {
doc,
groups,
name,
private,
..
} => {
if let Some(absolute) = absolute {
Expand All @@ -81,6 +86,7 @@ impl<'run, 'src> Analyzer<'run, 'src> {
loaded,
Some(*name),
paths,
*private,
absolute,
)?);
}
Expand Down Expand Up @@ -231,6 +237,7 @@ impl<'run, 'src> Analyzer<'run, 'src> {
module_path: ast.module_path.clone(),
modules: self.modules,
name,
private,
recipes,
settings,
source,
Expand Down
3 changes: 2 additions & 1 deletion src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Compiler {
asts.insert(current.path, ast.clone());
}

let justfile = Analyzer::analyze(&asts, config, None, &[], &loaded, None, &paths, root)?;
let justfile = Analyzer::analyze(&asts, config, None, &[], &loaded, None, &paths, false, root)?;

Ok(Compilation {
asts,
Expand Down Expand Up @@ -234,6 +234,7 @@ impl Compiler {
&[],
None,
&paths,
false,
&root,
)
}
Expand Down
1 change: 1 addition & 0 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) enum Item<'src> {
groups: Vec<StringLiteral<'src>>,
name: Name<'src>,
optional: bool,
private: bool,
relative: Option<StringLiteral<'src>>,
},
Recipe(UnresolvedRecipe<'src>),
Expand Down
12 changes: 9 additions & 3 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub(crate) struct Justfile<'src> {
pub(crate) modules: Table<'src, Justfile<'src>>,
#[serde(skip)]
pub(crate) name: Option<Name<'src>>,
#[serde(skip)]
pub(crate) private: bool,
pub(crate) recipes: Table<'src, Arc<Recipe<'src>>>,
pub(crate) settings: Settings,
pub(crate) source: PathBuf,
Expand Down Expand Up @@ -391,8 +393,12 @@ impl<'src> Justfile<'src> {
Ok(())
}

pub(crate) fn modules(&self, config: &Config) -> Vec<&Justfile> {
let mut modules = self.modules.values().collect::<Vec<&Justfile>>();
pub(crate) fn public_modules(&self, config: &Config) -> Vec<&Justfile> {
let mut modules = self
.modules
.values()
.filter(|module| !module.private)
.collect::<Vec<&Justfile>>();

if config.unsorted {
modules.sort_by_key(|module| {
Expand Down Expand Up @@ -440,7 +446,7 @@ impl<'src> Justfile<'src> {
}
}

for submodule in self.modules.values() {
for submodule in self.public_modules(config) {
for group in submodule.groups() {
groups.push((&[], submodule.name.unwrap().offset, group.to_string()));
}
Expand Down
11 changes: 9 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,11 @@ impl<'run, 'src> Parser<'run, 'src> {
attributes.ensure_valid_attributes(
"Module",
*name,
&[AttributeDiscriminant::Doc, AttributeDiscriminant::Group],
&[
AttributeDiscriminant::Doc,
AttributeDiscriminant::Group,
AttributeDiscriminant::Private,
],
)?;

let doc = match attributes.get(AttributeDiscriminant::Doc) {
Expand All @@ -423,6 +427,8 @@ impl<'run, 'src> Parser<'run, 'src> {
_ => unreachable!(),
};

let private = attributes.contains(AttributeDiscriminant::Private);

let mut groups = Vec::new();
for attribute in attributes {
if let Attribute::Group(group) = attribute {
Expand All @@ -431,11 +437,12 @@ impl<'run, 'src> Parser<'run, 'src> {
}

items.push(Item::Module {
groups,
absolute: None,
doc,
groups,
name,
optional,
private,
relative,
});
}
Expand Down
8 changes: 5 additions & 3 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ impl Subcommand {
}
}
if !config.list_submodules {
for (name, _) in &module.modules {
for submodule in module.public_modules(config) {
let name = submodule.name();
signature_widths.insert(name, UnicodeWidthStr::width(format!("{name} ...").as_str()));
}
}
Expand Down Expand Up @@ -589,7 +590,7 @@ impl Subcommand {

let submodule_groups = {
let mut groups = BTreeMap::<Option<String>, Vec<&Justfile>>::new();
for submodule in module.modules(config) {
for submodule in module.public_modules(config) {
let submodule_groups = submodule.groups();
if submodule_groups.is_empty() {
groups.entry(None).or_default().push(submodule);
Expand Down Expand Up @@ -752,7 +753,8 @@ impl Subcommand {
*printed += 1;
}

for (name, module) in &justfile.modules {
for module in justfile.public_modules(config) {
let name = module.name();
components.push(name);
Self::summary_recursive(config, components, printed, module);
components.pop();
Expand Down
1 change: 1 addition & 0 deletions src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub(crate) fn analysis_error(
&[],
None,
&paths,
false,
&root,
) {
Ok(_) => panic!("Analysis unexpectedly succeeded"),
Expand Down
23 changes: 23 additions & 0 deletions tests/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ fn private_attribute_for_alias() {
.run();
}

#[test]
fn private_attribute_for_module() {
Test::new()
.write("foo.just", "bar:")
.justfile(
r"
[private]
mod foo

baz:
",
)
.test_round_trip(false)
.arg("--list")
.stdout(
"
Available recipes:
baz
",
)
.run();
}

#[test]
fn private_variables_are_not_listed() {
Test::new()
Expand Down