Skip to content

Commit 687007a

Browse files
authored
Stabilize modules (#2250)
1 parent 6747c79 commit 687007a

20 files changed

+96
-226
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,10 @@ $ cat foo.just
667667
mod bar
668668
$ cat bar.just
669669
baz:
670-
$ just --unstable foo bar
670+
$ just foo bar
671671
Available recipes:
672672
baz
673-
$ just --unstable foo::bar
673+
$ just foo::bar
674674
Available recipes:
675675
baz
676676
```
@@ -3154,9 +3154,11 @@ Missing source files for optional imports do not produce an error.
31543154

31553155
### Modules<sup>1.19.0</sup>
31563156

3157-
A `justfile` can declare modules using `mod` statements. `mod` statements are
3158-
currently unstable, so you'll need to use the `--unstable` flag,
3159-
`set unstable`, or set the `JUST_UNSTABLE` environment variable to use them.
3157+
A `justfile` can declare modules using `mod` statements.
3158+
3159+
`mod` statements were stabilized in `just`<sup>master</sup>. In earlier
3160+
versions, you'll need to use the `--unstable` flag, `set unstable`, or set the
3161+
`JUST_UNSTABLE` environment variable to use them.
31603162

31613163
If you have the following `justfile`:
31623164

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

31833185
```sh
3184-
$ just --unstable bar b
3186+
$ just bar b
31853187
B
31863188
```
31873189

31883190
Or with path syntax:
31893191

31903192
```sh
3191-
$ just --unstable bar::b
3193+
$ just bar::b
31923194
B
31933195
```
31943196

src/analyzer.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ impl<'src> Analyzer<'src> {
3737

3838
let mut warnings = Vec::new();
3939

40-
let mut unstable = BTreeSet::new();
41-
4240
let mut modules: Table<Justfile> = Table::new();
4341

4442
let mut unexports: HashSet<String> = HashSet::new();
@@ -94,8 +92,6 @@ impl<'src> Analyzer<'src> {
9492
doc,
9593
..
9694
} => {
97-
unstable.insert(Unstable::Modules);
98-
9995
if let Some(absolute) = absolute {
10096
define(*name, "module", false)?;
10197
modules.insert(Self::analyze(
@@ -198,7 +194,7 @@ impl<'src> Analyzer<'src> {
198194
settings,
199195
source: root.into(),
200196
unexports,
201-
unstable,
197+
unstable_features: BTreeSet::new(),
202198
warnings,
203199
})
204200
}

src/config.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,15 @@ impl Config {
720720
})
721721
}
722722

723-
pub(crate) fn require_unstable(&self, message: &str) -> RunResult<'static> {
724-
if self.unstable {
723+
pub(crate) fn require_unstable(
724+
&self,
725+
justfile: &Justfile,
726+
unstable_feature: UnstableFeature,
727+
) -> RunResult<'static> {
728+
if self.unstable || justfile.settings.unstable {
725729
Ok(())
726730
} else {
727-
Err(Error::Unstable {
728-
message: message.to_owned(),
729-
})
731+
Err(Error::UnstableFeature { unstable_feature })
730732
}
731733
}
732734

src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ pub(crate) enum Error<'src> {
174174
recipe: String,
175175
suggestion: Option<Suggestion<'src>>,
176176
},
177-
Unstable {
178-
message: String,
177+
UnstableFeature {
178+
unstable_feature: UnstableFeature,
179179
},
180180
WriteJustfile {
181181
justfile: PathBuf,
@@ -459,8 +459,8 @@ impl<'src> ColorDisplay for Error<'src> {
459459
write!(f, "\n{suggestion}")?;
460460
}
461461
}
462-
Unstable { message } => {
463-
write!(f, "{message} Invoke `just` with `--unstable`, set the `JUST_UNSTABLE` environment variable, or add `set unstable` to your `justfile` to enable unstable features.")?;
462+
UnstableFeature { unstable_feature } => {
463+
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.")?;
464464
}
465465
WriteJustfile { justfile, io_error } => {
466466
let justfile = justfile.display();

src/justfile.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pub(crate) struct Justfile<'src> {
2626
#[serde(skip)]
2727
pub(crate) source: PathBuf,
2828
pub(crate) unexports: HashSet<String>,
29-
pub(crate) warnings: Vec<Warning>,
3029
#[serde(skip)]
31-
pub(crate) unstable: BTreeSet<Unstable>,
30+
pub(crate) unstable_features: BTreeSet<UnstableFeature>,
31+
pub(crate) warnings: Vec<Warning>,
3232
}
3333

3434
impl<'src> Justfile<'src> {
@@ -228,12 +228,8 @@ impl<'src> Justfile<'src> {
228228
}
229229

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

239235
for module in self.modules.values() {

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) use {
4242
shell::Shell, show_whitespace::ShowWhitespace, source::Source, string_kind::StringKind,
4343
string_literal::StringLiteral, subcommand::Subcommand, suggestion::Suggestion, table::Table,
4444
thunk::Thunk, token::Token, token_kind::TokenKind, unresolved_dependency::UnresolvedDependency,
45-
unresolved_recipe::UnresolvedRecipe, unstable::Unstable, use_color::UseColor,
45+
unresolved_recipe::UnresolvedRecipe, unstable_feature::UnstableFeature, use_color::UseColor,
4646
variables::Variables, verbosity::Verbosity, warning::Warning,
4747
},
4848
camino::Utf8Path,
@@ -204,7 +204,7 @@ mod token_kind;
204204
mod unindent;
205205
mod unresolved_dependency;
206206
mod unresolved_recipe;
207-
mod unstable;
207+
mod unstable_feature;
208208
mod use_color;
209209
mod variables;
210210
mod verbosity;

src/subcommand.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Subcommand {
7979
justfile.run(config, &search, overrides, &[])?;
8080
}
8181
Dump => Self::dump(config, ast, justfile)?,
82-
Format => Self::format(config, &search, src, ast)?,
82+
Format => Self::format(config, &search, src, ast, justfile)?,
8383
Groups => Self::groups(config, justfile),
8484
List { path } => Self::list(config, justfile, path)?,
8585
Show { path } => Self::show(config, justfile, path)?,
@@ -337,8 +337,14 @@ impl Subcommand {
337337
Ok(())
338338
}
339339

340-
fn format(config: &Config, search: &Search, src: &str, ast: &Ast) -> RunResult<'static> {
341-
config.require_unstable("The `--fmt` command is currently unstable.")?;
340+
fn format(
341+
config: &Config,
342+
search: &Search,
343+
src: &str,
344+
ast: &Ast,
345+
justfile: &Justfile,
346+
) -> RunResult<'static> {
347+
config.require_unstable(justfile, UnstableFeature::FormatSubcommand)?;
342348

343349
let formatted = ast.to_string();
344350

src/unstable.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/unstable_feature.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use super::*;
2+
3+
#[derive(Copy, Clone, Debug, PartialEq, Ord, Eq, PartialOrd)]
4+
pub(crate) enum UnstableFeature {
5+
FormatSubcommand,
6+
}
7+
8+
impl Display for UnstableFeature {
9+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
10+
match self {
11+
Self::FormatSubcommand => write!(f, "The `--fmt` command is currently unstable."),
12+
}
13+
}
14+
}

tests/choose.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ fn recipes_in_submodules_can_be_chosen() {
8686
.args(["--unstable", "--choose"])
8787
.env("JUST_CHOOSER", "head -n10")
8888
.write("bar.just", "baz:\n echo BAZ")
89-
.test_round_trip(false)
9089
.justfile(
9190
"
9291
mod bar

0 commit comments

Comments
 (0)