Add CliConfig helper methods to reduce accessor boilerplate

Add app_id(), slug(), and git_author() methods to CliConfig to
replace repeated .git.as_ref().and_then(...) chains across 5 call
sites in main.rs and doctor.rs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-03-10 13:21:06 -04:00
parent c32e74fbb4
commit 2969c98057
3 changed files with 20 additions and 11 deletions

View file

@ -1019,7 +1019,7 @@ pub async fn run_doctor(verbose: bool, live: bool) -> i32 {
allowed_usernames_count: server_config.web.auth.allowed_usernames.len(),
};
let git_app_id = cli_config.git.as_ref().and_then(|g| g.app_id.clone());
let git_app_id = cli_config.app_id().map(str::to_owned);
let private_key_raw = std::env::var("GITHUB_APP_PRIVATE_KEY").ok();
let sign_result = match (&git_app_id, &private_key_raw) {
(Some(app_id), Some(raw)) => {
@ -1046,7 +1046,7 @@ pub async fn run_doctor(verbose: bool, live: bool) -> i32 {
};
let github_status = GithubAppStatus {
app_id: git_app_id,
slug: cli_config.git.as_ref().and_then(|g| g.slug.clone()),
slug: cli_config.slug().map(str::to_owned),
private_key_set: private_key_raw.is_some(),
sign_result,
#[cfg(feature = "server")]

View file

@ -324,14 +324,11 @@ async fn main_inner() -> Result<()> {
Box::leak(Box::new(arc_util::terminal::Styles::detect_stderr()));
let cli_config = cli_config::load_cli_config(None)?;
args.verbose = args.verbose || cli_config.verbose;
let github_app = build_github_app_credentials(
cli_config.git.as_ref().and_then(|g| g.app_id.as_deref()),
);
let github_app = build_github_app_credentials(cli_config.app_id());
let cli_author = cli_config.git.as_ref().map(|g| &g.author);
let git_author = arc_workflows::git::GitAuthor::from_options(
cli_author.and_then(|a| a.name.clone()),
cli_author.and_then(|a| a.email.clone()),
cli_config.git_author().and_then(|a| a.name.clone()),
cli_config.git_author().and_then(|a| a.email.clone()),
);
arc_workflows::cli::run::run_command(
@ -402,9 +399,7 @@ async fn main_inner() -> Result<()> {
Command::Pr { command } => match command {
PrCommand::Create(args) => {
let cli_config = cli_config::load_cli_config(None)?;
let github_app = build_github_app_credentials(
cli_config.git.as_ref().and_then(|g| g.app_id.as_deref()),
);
let github_app = build_github_app_credentials(cli_config.app_id());
arc_workflows::cli::pr::pr_create_command(args, github_app).await?;
}
},

View file

@ -81,6 +81,20 @@ pub struct CliConfig {
pub mcp_servers: HashMap<String, McpServerEntry>,
}
impl CliConfig {
pub fn app_id(&self) -> Option<&str> {
self.git.as_ref().and_then(|g| g.app_id.as_deref())
}
pub fn slug(&self) -> Option<&str> {
self.git.as_ref().and_then(|g| g.slug.as_deref())
}
pub fn git_author(&self) -> Option<&crate::server::GitAuthorConfig> {
self.git.as_ref().map(|g| &g.author)
}
}
/// Load CLI config from an explicit path or `~/.arc/cli.toml`, returning defaults if the
/// default file doesn't exist. An explicit path that doesn't exist is an error.
pub fn load_cli_config(path: Option<&Path>) -> anyhow::Result<CliConfig> {