Skip to content

Commit 4f88e0d

Browse files
committed
new: Add moon toolchain commands. (#2022)
* Get info working. * Add command. * Add info tests. * Adda dd tests. * Remove init toolchain. * Add docs.
1 parent 066041d commit 4f88e0d

24 files changed

Lines changed: 610 additions & 208 deletions

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
#### 🚀 Updates
66

7-
- Added support for terminal desktop notifications. Can be enabled with the new
8-
`notifier.terminalNotifications` setting in `.moon/workspace.yml`.
9-
- Added new MCP tools.
7+
- Added new tools for `moon mcp`.
108
- `get_touched_files` - Gets touched files between base and head.
119
- `sync_projects` - Runs the `SyncProject` action for one or many projects.
1210
- `sync_workspace` - Runs the `SyncWorkspace` action.
11+
- Added new `moon toolchain` command and sub-commands.
12+
- Add a toolchain to `.moon/toolchain.yml` with `moon toolchain add`.
13+
- View information about a toolchain plugin with `moon toolchain info`.
14+
- Added support for terminal desktop notifications. Can be enabled with the new
15+
`notifier.terminalNotifications` setting in `.moon/workspace.yml`.
1316

1417
#### ⚙️ Internal
1518

crates/app/src/app.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,35 @@ pub struct Cli {
285285
global = true,
286286
env = "MOON_CACHE",
287287
help = "Mode for cache operations",
288+
help_heading = "Global options",
288289
default_value_t
289290
)]
290291
pub cache: CacheMode,
291292

292-
#[arg(long, global = true, help = "Force colored output")]
293+
#[arg(
294+
long,
295+
global = true,
296+
help = "Force colored output",
297+
help_heading = "Global options"
298+
)]
293299
pub color: bool,
294300

295301
#[arg(
296302
long,
297303
short = 'c',
298304
global = true,
299305
env = "MOON_CONCURRENCY",
300-
help = "Maximum number of threads to utilize"
306+
help = "Maximum number of threads to utilize",
307+
help_heading = "Global options"
301308
)]
302309
pub concurrency: Option<usize>,
303310

304311
#[arg(
305312
long,
306313
global = true,
307314
env = "MOON_DUMP",
308-
help = "Dump a trace profile to the working directory"
315+
help = "Dump a trace profile to the working directory",
316+
help_heading = "Global options"
309317
)]
310318
pub dump: bool,
311319

@@ -315,6 +323,7 @@ pub struct Cli {
315323
global = true,
316324
env = "MOON_LOG",
317325
help = "Lowest log level to output",
326+
help_heading = "Global options",
318327
default_value_t
319328
)]
320329
pub log: LogLevel,
@@ -323,7 +332,8 @@ pub struct Cli {
323332
long,
324333
global = true,
325334
env = "MOON_LOG_FILE",
326-
help = "Path to a file to write logs to"
335+
help = "Path to a file to write logs to",
336+
help_heading = "Global options"
327337
)]
328338
pub log_file: Option<PathBuf>,
329339

@@ -332,7 +342,8 @@ pub struct Cli {
332342
short = 'q',
333343
global = true,
334344
env = "MOON_QUIET",
335-
help = "Hide all non-important terminal output"
345+
help = "Hide all non-important terminal output",
346+
help_heading = "Global options"
336347
)]
337348
pub quiet: bool,
338349

@@ -342,6 +353,7 @@ pub struct Cli {
342353
global = true,
343354
env = "MOON_THEME",
344355
help = "Terminal theme to print with",
356+
help_heading = "Global options",
345357
default_value_t
346358
)]
347359
pub theme: AppTheme,

crates/app/src/app_error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ pub enum AppError {
6161
#[error("Upgrading moon requires an internet connection!")]
6262
UpgradeRequiresInternet,
6363

64+
#[diagnostic(
65+
code(app::plugin::locator_required),
66+
url = "https://moonrepo.dev/docs/guides/wasm-plugins#configuring-plugin-locations"
67+
)]
68+
#[error("A plugin locator string is required for non-built-in plugins.")]
69+
PluginLocatorRequired,
70+
6471
#[diagnostic(code(app::id_required))]
6572
#[error("A project ID is required.")]
6673
ProjectIdRequired,

crates/app/src/commands/init/bun.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ pub async fn init_bun(console: &Console, options: &InitOptions) -> miette::Resul
5353
})?;
5454
}
5555

56-
let bun_version = render_version_prompt(console, options, "Bun", || Ok(None)).await?;
56+
let bun_version =
57+
render_version_prompt(console, options.yes || options.minimal, "Bun", || Ok(None)).await?;
5758

5859
let sync_dependencies = render_prompt(
5960
console,
60-
options,
61+
options.yes,
6162
&SettingPrompt::new(
6263
"syncDependencies",
6364
"Sync project relationships as <file>package.json</file> <property>dependencies</property>?",

crates/app/src/commands/init/mod.rs

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
mod bun;
22
mod node;
3-
mod prompts;
3+
pub mod prompts;
44
mod rust;
5-
mod toolchain;
65

76
use crate::session::MoonSession;
87
use bun::init_bun;
@@ -11,25 +10,22 @@ use clean_path::Clean;
1110
use iocraft::prelude::{FlexDirection, View, element};
1211
use miette::IntoDiagnostic;
1312
use moon_common::{Id, consts::CONFIG_DIRNAME, is_test_env};
14-
use moon_config::{
15-
ToolchainConfig, load_toolchain_config_template, load_workspace_config_template,
16-
};
13+
use moon_config::{load_toolchain_config_template, load_workspace_config_template};
1714
use moon_console::{
1815
Console,
1916
ui::{Confirm, Container, Notice, StyledText, Variant},
2017
};
2118
use moon_vcs::{Git, Vcs};
2219
use node::init_node;
23-
use proto_core::{Id as PluginId, PluginLocator};
20+
use proto_core::PluginLocator;
2421
use rust::init_rust;
2522
use starbase::AppResult;
2623
use starbase_styles::color;
2724
use starbase_utils::fs;
2825
use std::collections::BTreeMap;
2926
use std::path::PathBuf;
3027
use tera::{Context, Tera};
31-
use toolchain::init_toolchain;
32-
use tracing::instrument;
28+
use tracing::{instrument, warn};
3329

3430
#[derive(Args, Clone, Debug)]
3531
pub struct InitArgs {
@@ -164,41 +160,12 @@ pub async fn init_for_toolchain(
164160
"node" => init_node(console, options).await?,
165161
"rust" => init_rust(console, options).await?,
166162
_ => {
167-
let mut include_locator = true;
168-
let plugin_id = PluginId::raw(id.as_str());
169-
let plugin_locator = match args.plugin.as_ref() {
170-
Some(locator) => locator.to_owned(),
171-
None => match ToolchainConfig::get_plugin_locator(id) {
172-
Some(locator) => {
173-
include_locator = false;
174-
locator
175-
}
176-
None => {
177-
console.err.write_line(
178-
"A plugin locator is required as the 2nd argument when initializing a toolchain!"
179-
)?;
180-
181-
return Ok(Some(1));
182-
}
183-
},
184-
};
185-
186-
let toolchain_registry = session.get_toolchain_registry().await?;
187-
188-
toolchain_registry
189-
.load_without_config(&plugin_id, plugin_locator)
190-
.await?;
191-
192-
let toolchain = toolchain_registry.get_instance(&plugin_id).await?;
163+
warn!(
164+
"This command has been deprecated for toolchain plugins, use {} instead.",
165+
color::shell(format!("moon toolchain add {}", id))
166+
);
193167

194-
init_toolchain(
195-
&session.console,
196-
options,
197-
&toolchain_registry,
198-
&toolchain,
199-
include_locator,
200-
)
201-
.await?
168+
return Ok(None);
202169
}
203170
};
204171

crates/app/src/commands/init/node.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async fn detect_package_manager(
8383
if pm_type.is_empty() {
8484
let pm = render_prompt(
8585
console,
86-
options,
86+
options.yes,
8787
&SettingPrompt::new(
8888
"packageManager",
8989
"Package manager?",
@@ -100,14 +100,15 @@ async fn detect_package_manager(
100100
}
101101
}
102102

103-
let pm_version = render_version_prompt(console, options, &pm_type, || {
104-
if pm_version.is_empty() {
105-
Ok(None)
106-
} else {
107-
Ok(UnresolvedVersionSpec::parse(&pm_version).ok())
108-
}
109-
})
110-
.await?;
103+
let pm_version =
104+
render_version_prompt(console, options.yes || options.minimal, &pm_type, || {
105+
if pm_version.is_empty() {
106+
Ok(None)
107+
} else {
108+
Ok(UnresolvedVersionSpec::parse(&pm_version).ok())
109+
}
110+
})
111+
.await?;
111112

112113
Ok((pm_type, pm_version))
113114
}
@@ -151,13 +152,16 @@ pub async fn init_node(console: &Console, options: &InitOptions) -> miette::Resu
151152
}
152153

153154
let node_version =
154-
render_version_prompt(console, options, "Node", || detect_node_version(options)).await?;
155+
render_version_prompt(console, options.yes || options.minimal, "Node", || {
156+
detect_node_version(options)
157+
})
158+
.await?;
155159
let node_version_manager = detect_node_version_manager(options)?;
156160
let package_manager = detect_package_manager(console, options).await?;
157161

158162
let infer_tasks = render_prompt(
159163
console,
160-
options,
164+
options.yes,
161165
&SettingPrompt::new(
162166
"inferTasks",
163167
"Infer <file>package.json</file> scripts as moon tasks? <muted>(not recommended)</muted>",
@@ -168,7 +172,7 @@ pub async fn init_node(console: &Console, options: &InitOptions) -> miette::Resu
168172

169173
let sync_dependencies = render_prompt(
170174
console,
171-
options,
175+
options.yes,
172176
&SettingPrompt::new(
173177
"syncDependencies",
174178
"Sync project relationships as <file>package.json</file> <property>dependencies</property>?",
@@ -179,7 +183,7 @@ pub async fn init_node(console: &Console, options: &InitOptions) -> miette::Resu
179183

180184
let dedupe_lockfile = render_prompt(
181185
console,
182-
options,
186+
options.yes,
183187
&SettingPrompt::new(
184188
"dedupeLockfile",
185189
"Automatically dedupe lockfile when changed?",

crates/app/src/commands/init/prompts.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::InitOptions;
21
use iocraft::prelude::element;
32
use moon_console::{
43
Console,
@@ -27,13 +26,13 @@ pub fn fully_qualify_version(version: String) -> Option<String> {
2726

2827
pub async fn render_prompt(
2928
console: &Console,
30-
options: &InitOptions,
29+
skip_prompts: bool,
3130
prompt: &SettingPrompt,
3231
) -> miette::Result<Option<JsonValue>> {
3332
match &prompt.ty {
3433
PromptType::None => Ok(None),
3534
PromptType::Confirm { default } => {
36-
let result = if options.yes {
35+
let result = if skip_prompts {
3736
*default
3837
} else {
3938
let mut value = *default;
@@ -54,7 +53,7 @@ pub async fn render_prompt(
5453
Ok(Some(JsonValue::Bool(result)))
5554
}
5655
PromptType::Input { default } => {
57-
let result = if options.yes {
56+
let result = if skip_prompts {
5857
default.to_owned()
5958
} else {
6059
let mut value = default.to_owned();
@@ -87,7 +86,7 @@ pub async fn render_prompt(
8786
default_index,
8887
options: items,
8988
} => {
90-
let index = if options.yes {
89+
let index = if skip_prompts {
9190
*default_index
9291
} else {
9392
let mut index = *default_index;
@@ -114,13 +113,13 @@ pub async fn render_prompt(
114113

115114
pub async fn render_version_prompt(
116115
console: &Console,
117-
options: &InitOptions,
116+
skip_prompts: bool,
118117
tool: &str,
119118
op: impl FnOnce() -> miette::Result<Option<UnresolvedVersionSpec>>,
120119
) -> miette::Result<Option<UnresolvedVersionSpec>> {
121120
let default_version = op()?;
122121

123-
if options.yes || options.minimal {
122+
if skip_prompts {
124123
return Ok(default_version);
125124
}
126125

crates/app/src/commands/init/rust.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ pub async fn init_rust(console: &Console, options: &InitOptions) -> miette::Resu
7575
})?;
7676
}
7777

78-
let rust_version = render_version_prompt(console, options, "Rust", || {
79-
detect_rust_version(&options.dir)
80-
})
81-
.await?;
78+
let rust_version =
79+
render_version_prompt(console, options.yes || options.minimal, "Rust", || {
80+
detect_rust_version(&options.dir)
81+
})
82+
.await?;
8283

8384
let mut context = Context::new();
8485
if let Some(rust_version) = rust_version {

0 commit comments

Comments
 (0)