Skip to content

Commit 84179ab

Browse files
committed
only use worlds from componentize-go.toml files when not specified via CLI
Previously, we'd union all the worlds specified via the CLI _and_ via `componentize-go.toml` files, but that can get very confusing for the user. Now we'll only use the toml file ones as a default if none are specified via the CLI.
1 parent 7b229bb commit 84179ab

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/command.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ pub struct WitOpts {
4242
/// This may be specified more than once, in which case the worlds will be
4343
/// merged.
4444
///
45-
/// Note that, unless `--ignore-toml-files` is specified, `componentize-go`
46-
/// will also use `go list` to scan the current Go module and its
47-
/// dependencies to find any `componentize-go.toml` files. The WIT worlds
48-
/// referenced by any such files will be added to this list automatically.
45+
/// Note that, unless `--ignore-toml-files` _or_ at least one `--world`
46+
/// option is specified, `componentize-go` will use `go list` to scan the
47+
/// current Go module and its dependencies to find any
48+
/// `componentize-go.toml` files, and the WIT worlds referenced by any such
49+
/// files will be used.
4950
#[arg(long, short = 'w')]
5051
pub world: Vec<String>,
5152

src/utils.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ fn maybe_add_dependencies(
108108
.map(|v| PathBuf::from(v.as_ref()))
109109
.collect::<BTreeSet<_>>();
110110
let mut worlds = worlds.iter().cloned().collect::<BTreeSet<_>>();
111+
// Only add worlds from `componentize-go.toml` files if none were specified
112+
// explicitly via the CLI:
113+
let add_worlds = worlds.is_empty();
111114

112115
if !ignore_toml_files && Path::new("go.mod").exists() {
113116
let mut command = std::process::Command::new("go");
@@ -133,7 +136,9 @@ fn maybe_add_dependencies(
133136
let module = PathBuf::from(module);
134137
if let Ok(manifest) = std::fs::read_to_string(module.join("componentize-go.toml")) {
135138
let config = toml::from_str::<ComponentizeGoConfig>(&manifest)?;
136-
worlds.extend(config.worlds);
139+
if add_worlds {
140+
worlds.extend(config.worlds);
141+
}
137142
paths.extend(config.wit_paths.into_iter().map(|v| module.join(v)));
138143
}
139144
}

0 commit comments

Comments
 (0)