Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize modules #2250

Merged
merged 6 commits into from
Jul 14, 2024
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
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 667,10 @@ $ cat foo.just
mod bar
$ cat bar.just
baz:
$ just --unstable foo bar
$ just foo bar
Available recipes:
baz
$ just --unstable foo::bar
$ just foo::bar
Available recipes:
baz
```
Expand Down Expand Up @@ -3154,9 3154,11 @@ Missing source files for optional imports do not produce an error.

### Modules<sup>1.19.0</sup>

A `justfile` can declare modules using `mod` statements. `mod` statements are
currently unstable, so you'll need to use the `--unstable` flag,
`set unstable`, or set the `JUST_UNSTABLE` environment variable to use them.
A `justfile` can declare modules using `mod` statements.

`mod` statements were stabilized in `just`<sup>master</sup>. In earlier
versions, you'll need to use the `--unstable` flag, `set unstable`, or set the
`JUST_UNSTABLE` environment variable to use them.

If you have the following `justfile`:

Expand All @@ -3181,14 3183,14 @@ uses its own settings.
Recipes in submodules can be invoked as subcommands:

```sh
$ just --unstable bar b
$ just bar b
B
```

Or with path syntax:

```sh
$ just --unstable bar::b
$ just bar::b
B
```

Expand Down
6 changes: 1 addition & 5 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 37,6 @@ impl<'src> Analyzer<'src> {

let mut warnings = Vec::new();

let mut unstable = BTreeSet::new();

let mut modules: Table<Justfile> = Table::new();

let mut unexports: HashSet<String> = HashSet::new();
Expand Down Expand Up @@ -94,8 92,6 @@ impl<'src> Analyzer<'src> {
doc,
..
} => {
unstable.insert(Unstable::Modules);

if let Some(absolute) = absolute {
define(*name, "module", false)?;
modules.insert(Self::analyze(
Expand Down Expand Up @@ -198,7 194,7 @@ impl<'src> Analyzer<'src> {
settings,
source: root.into(),
unexports,
unstable,
unstable_features: BTreeSet::new(),
warnings,
})
}
Expand Down
12 changes: 7 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 720,15 @@ impl Config {
})
}

pub(crate) fn require_unstable(&self, message: &str) -> RunResult<'static> {
if self.unstable {
pub(crate) fn require_unstable(
&self,
justfile: &Justfile,
unstable_feature: UnstableFeature,
) -> RunResult<'static> {
if self.unstable || justfile.settings.unstable {
Ok(())
} else {
Err(Error::Unstable {
message: message.to_owned(),
})
Err(Error::UnstableFeature { unstable_feature })
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 174,8 @@ pub(crate) enum Error<'src> {
recipe: String,
suggestion: Option<Suggestion<'src>>,
},
Unstable {
message: String,
UnstableFeature {
unstable_feature: UnstableFeature,
},
WriteJustfile {
justfile: PathBuf,
Expand Down Expand Up @@ -459,8 459,8 @@ impl<'src> ColorDisplay for Error<'src> {
write!(f, "\n{suggestion}")?;
}
}
Unstable { message } => {
write!(f, "{message} Invoke `just` with `--unstable`, set the `JUST_UNSTABLE` environment variable, or add `set unstable` to your `justfile` to enable unstable features.")?;
UnstableFeature { unstable_feature } => {
write!(f, "{unstable_feature} Invoke `just` with `--unstable`, set the `JUST_UNSTABLE` environment variable, or add `set unstable` to your `justfile` to enable unstable features.")?;
}
WriteJustfile { justfile, io_error } => {
let justfile = justfile.display();
Expand Down
12 changes: 4 additions & 8 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 26,9 @@ pub(crate) struct Justfile<'src> {
#[serde(skip)]
pub(crate) source: PathBuf,
pub(crate) unexports: HashSet<String>,
pub(crate) warnings: Vec<Warning>,
#[serde(skip)]
pub(crate) unstable: BTreeSet<Unstable>,
pub(crate) unstable_features: BTreeSet<UnstableFeature>,
pub(crate) warnings: Vec<Warning>,
}

impl<'src> Justfile<'src> {
Expand Down Expand Up @@ -228,12 228,8 @@ impl<'src> Justfile<'src> {
}

pub(crate) fn check_unstable(&self, config: &Config) -> RunResult<'src> {
if !config.unstable && !self.settings.unstable {
if let Some(unstable) = self.unstable.iter().next() {
return Err(Error::Unstable {
message: unstable.message(),
});
}
if let Some(&unstable_feature) = self.unstable_features.iter().next() {
config.require_unstable(self, unstable_feature)?;
}

for module in self.modules.values() {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 42,7 @@ pub(crate) use {
shell::Shell, show_whitespace::ShowWhitespace, source::Source, string_kind::StringKind,
string_literal::StringLiteral, subcommand::Subcommand, suggestion::Suggestion, table::Table,
thunk::Thunk, token::Token, token_kind::TokenKind, unresolved_dependency::UnresolvedDependency,
unresolved_recipe::UnresolvedRecipe, unstable::Unstable, use_color::UseColor,
unresolved_recipe::UnresolvedRecipe, unstable_feature::UnstableFeature, use_color::UseColor,
variables::Variables, verbosity::Verbosity, warning::Warning,
},
camino::Utf8Path,
Expand Down Expand Up @@ -204,7 204,7 @@ mod token_kind;
mod unindent;
mod unresolved_dependency;
mod unresolved_recipe;
mod unstable;
mod unstable_feature;
mod use_color;
mod variables;
mod verbosity;
Expand Down
12 changes: 9 additions & 3 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 79,7 @@ impl Subcommand {
justfile.run(config, &search, overrides, &[])?;
}
Dump => Self::dump(config, ast, justfile)?,
Format => Self::format(config, &search, src, ast)?,
Format => Self::format(config, &search, src, ast, justfile)?,
Groups => Self::groups(config, justfile),
List { path } => Self::list(config, justfile, path)?,
Show { path } => Self::show(config, justfile, path)?,
Expand Down Expand Up @@ -337,8 337,14 @@ impl Subcommand {
Ok(())
}

fn format(config: &Config, search: &Search, src: &str, ast: &Ast) -> RunResult<'static> {
config.require_unstable("The `--fmt` command is currently unstable.")?;
fn format(
config: &Config,
search: &Search,
src: &str,
ast: &Ast,
justfile: &Justfile,
) -> RunResult<'static> {
config.require_unstable(justfile, UnstableFeature::FormatSubcommand)?;

let formatted = ast.to_string();

Expand Down
12 changes: 0 additions & 12 deletions src/unstable.rs

This file was deleted.

14 changes: 14 additions & 0 deletions src/unstable_feature.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,14 @@
use super::*;

#[derive(Copy, Clone, Debug, PartialEq, Ord, Eq, PartialOrd)]
pub(crate) enum UnstableFeature {
FormatSubcommand,
}

impl Display for UnstableFeature {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::FormatSubcommand => write!(f, "The `--fmt` command is currently unstable."),
}
}
}
1 change: 0 additions & 1 deletion tests/choose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 86,6 @@ fn recipes_in_submodules_can_be_chosen() {
.args(["--unstable", "--choose"])
.env("JUST_CHOOSER", "head -n10")
.write("bar.just", "baz:\n echo BAZ")
.test_round_trip(false)
.justfile(
"
mod bar
Expand Down
9 changes: 2 additions & 7 deletions tests/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 864,6 @@ fn source_file() {

Test::new()
.args(["--evaluate", "x"])
.test_round_trip(false)
.justfile(
"
import 'foo.just'
Expand All @@ -875,8 874,7 @@ fn source_file() {
.run();

Test::new()
.args(["--unstable", "foo", "bar"])
.test_round_trip(false)
.args(["foo", "bar"])
.justfile(
"
mod foo
Expand All @@ -890,8 888,7 @@ fn source_file() {
#[test]
fn source_directory() {
Test::new()
.args(["--unstable", "foo", "bar"])
.test_round_trip(false)
.args(["foo", "bar"])
.justfile(
"
mod foo
Expand Down Expand Up @@ -984,9 981,7 @@ import-outer: import-inner
echo '{{ module_directory() }}'
",
)
.test_round_trip(false)
.args([
"--unstable",
"outer",
"import-outer",
"baz",
Expand Down
Loading