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
14 changes: 7 additions & 7 deletions crates/cargo-gears-core/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ pub struct AppConfig {
/// OpenTelemetry configuration (resource, tracing, metrics).
#[serde(default)]
pub opentelemetry: OpenTelemetryConfig,
/// Directory containing per-module YAML files (optional).
/// Directory containing per-gear YAML files (optional).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub modules_dir: Option<String>,
/// Per-module configuration bag: `module_name` -> module config.
pub gears_dir: Option<String>,
/// Per-gear configuration bag: `gear_name` -> gear config.
#[serde(default)]
pub modules: BTreeMap<String, ModuleConfig>,
pub gears: BTreeMap<String, ModuleConfig>,
/// Per-vendor configuration bag: `vendor_name` → arbitrary JSON/YAML value.
/// Allows vendors to add their own typed configuration sections.
#[serde(default)]
Expand All @@ -36,7 +36,7 @@ pub struct AppConfig {
impl AppConfig {
pub fn create_dependencies(self) -> anyhow::Result<CargoTomlDependencies> {
let mut dependencies = CargoTomlDependencies::new();
for (name, module) in self.modules {
for (name, module) in self.gears {
if matches!(
module.runtime.as_ref().map(|r| &r.mod_type),
Some(RuntimeKind::Oop)
Expand Down Expand Up @@ -80,8 +80,8 @@ impl Default for AppConfig {
database: None,
logging: default_logging_config(),
opentelemetry: OpenTelemetryConfig::default(),
modules_dir: None,
modules: BTreeMap::new(),
gears_dir: None,
gears: BTreeMap::new(),
vendor: VendorConfig::default(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-gears-core/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub fn get_config(workspace_root: &Path, config_path: &Path) -> anyhow::Result<A
let mut config = get_config_from_path(config_path)?;
let mut members = get_module_name_from_crate(Some(workspace_root))?;

config.modules.iter_mut().for_each(|module| {
config.gears.iter_mut().for_each(|module| {
if let Some(module_metadata) = members.remove(module.0.as_str()) {
let config_metadata = std::mem::take(&mut module.1.metadata).unwrap_or_default();
module.1.metadata = Some(merge_module_metadata(
Expand Down
6 changes: 3 additions & 3 deletions crates/cargo-gears-core/src/config/modules/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl AddParams {
}

fn upsert_module_config(config: &mut AppConfig, args: &AddParams, incoming: ConfigModuleMetadata) {
let module_config = config.modules.entry(args.module.clone()).or_default();
let module_config = config.gears.entry(args.module.clone()).or_default();
let merged_metadata = if let Some(existing) = module_config.metadata.take() {
merge_module_metadata(existing, incoming, args)
} else {
Expand Down Expand Up @@ -285,7 +285,7 @@ mod tests {
#[test]
fn upsert_module_config_preserves_existing_metadata_when_cli_fields_not_provided() {
let mut config = AppConfig::default();
config.modules.insert(
config.gears.insert(
"demo".to_owned(),
ModuleConfig {
metadata: Some(ConfigModuleMetadata {
Expand Down Expand Up @@ -327,7 +327,7 @@ mod tests {
upsert_module_config(&mut config, &args, incoming);

let metadata = &config
.modules
.gears
.get("demo")
.and_then(|module| module.metadata.as_ref())
.expect("metadata should be present after upsert");
Expand Down
4 changes: 2 additions & 2 deletions crates/cargo-gears-core/src/config/modules/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl AddArgs {
validate_module_db_payload(&self.module, &self.conn)?;

let mut config = load_config(config_path)?;
if !config.modules.contains_key(&self.module) {
if !config.gears.contains_key(&self.module) {
bail!(
"module '{}' not found in {}; use `config mod add` first",
self.module,
Expand Down Expand Up @@ -123,7 +123,7 @@ fn get_module_cfg_mut<'a>(
config_path: &Path,
) -> anyhow::Result<&'a mut ModuleConfig> {
config
.modules
.gears
.get_mut(module)
.with_context(|| format!("module '{module}' not found in {}", config_path.display()))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-gears-core/src/config/modules/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl RemoveParams {
validate_module_name(&self.module)?;

let mut config = load_config(config_path)?;
if config.modules.remove(&self.module).is_none() {
if config.gears.remove(&self.module).is_none() {
let module = &self.module;
bail!("module '{module}' not found in modules section");
}
Expand Down
8 changes: 4 additions & 4 deletions crates/cargo-gears-core/src/help/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ fn schema_config(section: Option<&str>) -> anyhow::Result<String> {
out.push_str(&MetricsConfig::help_text());
Ok(out)
}
Some("modules") => {
Some("gears") => {
let mut out = ModuleConfig::help_text();
out.push('\n');
out.push_str(&ModuleRuntime::help_text());
Ok(out)
}
Comment on lines +264 to 269
Some(other) => bail!(
"unknown config section '{other}'; available: server, database, logging, opentelemetry, modules"
"unknown config section '{other}'; available: server, database, logging, opentelemetry, gears"
),
Comment on lines 270 to 272
Comment on lines 270 to 272
}
}
Expand Down Expand Up @@ -312,12 +312,12 @@ mod tests {
let text = schema_config(None).expect("overview should succeed");
assert!(text.contains("AppConfig"));
assert!(text.contains("server"));
assert!(text.contains("modules"));
assert!(text.contains("gears"));
}

#[test]
fn schema_config_sections_resolve() {
for section in &["server", "database", "logging", "opentelemetry", "modules"] {
for section in &["server", "database", "logging", "opentelemetry", "gears"] {
assert!(
schema_config(Some(section)).is_ok(),
"section '{section}' should resolve"
Expand Down