Skip to main content

is_cli_explicit

Function is_cli_explicit 

Source
pub(crate) fn is_cli_explicit(matches: &ArgMatches, arg_id: &str) -> bool
Expand description

codex 0547 F5 (P3) fix: clap ValueSource 区分 “CLI 显式传” vs “默认值”.

之前用 self.gateway == "127.0.0.1:11111" 判 “CLI 没传” — 当用户显式--gateway 127.0.0.1:11111 (与默认值相等) 时被错判为 “未传” → TOML 配置 gateway override 反向. 违背 “CLI 始终覆盖配置文件” 契约.

同模式: bool 字段 (verbose / enable_trading / allow_real_trading) 之前用 if !self.field 判, 用户显式 --verbose 时反复 = false 也不能 区分 “CLI 没传 + TOML 也没设” 与 “CLI 显式 false (无 –no-flag)”. clap derive 不天然支持 --no-*, 所以 bool 字段的 explicit-false override 是 设计 limitation; 但 explicit-true 一定要尊重.

本 helper 接受 &ArgMatchesarg_id, 返 true 仅在 user explicitly 传 (而不是 default / env). 见 https://docs.rs/clap/latest/clap/parser/enum.ValueSource.html.