fix: accept a bool value for the CLI --auto-create-schema flag (#9450)

* fix: accept a value for the CLI --auto-create-schema flag

clap derives ArgAction::SetTrue for bool fields, so --auto-create-schema
took no value and could only set true, which is already the default.
Users could not turn automatic schema creation off from the CLI, unlike
metasrv's auto_create_schema = false.

Set action = clap::ArgAction::Set so the flag accepts an explicit
true/false value while keeping true as the default.

Signed-off-by: fengyue-xve <1759519137@qq.com>

* chore: enhance CLI argument for auto_create_schema option

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Signed-off-by: fengyue-xve <1759519137@qq.com>
Co-authored-by: dennis zhuang <killme2008@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
(cherry picked from commit 329edc88ec)
Signed-off-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
fengyue-xve
2026-10-12 12:49:20 +00:00
committed by WenyXu
parent 83014e20a4
commit 57df534869
+31 -1
View File
@@ -86,7 +86,13 @@ pub struct StoreConfig {
/// Automatically create PostgreSQL schema if it doesn't exist (default: true).
#[cfg(feature = "pg_kvbackend")]
#[clap(long, default_value_t = true)]
#[clap(
long,
default_value_t = true,
default_missing_value = "true",
num_args = 0..=1,
action = clap::ArgAction::Set
)]
pub auto_create_schema: bool,
/// TLS mode for backend store connections (etcd, PostgreSQL, MySQL)
@@ -223,3 +229,27 @@ impl StoreConfig {
}
}
}
#[cfg(all(test, feature = "pg_kvbackend"))]
mod tests {
use clap::Parser;
use super::StoreConfig;
#[test]
fn test_auto_create_schema_accepts_explicit_value() {
let config =
StoreConfig::try_parse_from(["store", "--auto-create-schema", "false"]).unwrap();
assert!(!config.auto_create_schema);
let config =
StoreConfig::try_parse_from(["store", "--auto-create-schema", "true"]).unwrap();
assert!(config.auto_create_schema);
}
#[test]
fn test_auto_create_schema_defaults_to_true() {
let config = StoreConfig::try_parse_from(["store"]).unwrap();
assert!(config.auto_create_schema);
}
}