feat(cli): wire defaultProject through init and all commands
Integrates the defaultProject config field across the entire CLI surface so that omitting `-p` now falls back to the configured default. Init command: - New `--default-project` flag on `lore init` (and robot-mode variant) - InitInputs.default_project: Option<String> passed through to run_init - Validation in run_init ensures the default matches a configured path - Interactive mode: when multiple projects are configured, prompts whether to set a default and which project to use - Robot mode: InitOutputJson now includes default_project (omitted when null) for downstream automation - Autocorrect dictionary updated with `--default-project` Command handlers applying effective_project(): - handle_issues: list filters use config default when -p omitted - handle_mrs: same cascading resolution for MR listing - handle_ingest: dry-run and full sync respect the default - handle_timeline: TimelineParams.project resolved via effective_project - handle_search: SearchCliFilters.project resolved via effective_project - handle_generate_docs: project filter cascades - handle_who: falls back to config.default_project when -p omitted - handle_count: both count subcommands respect the default - handle_discussions: discussion count filters respect the default Robot-docs: - init command schema updated with --default-project flag and response_schema showing default_project as string? - New config_notes section documents the defaultProject field with type, description, and example Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -193,6 +193,7 @@ const COMMAND_FLAGS: &[(&str, &[&str])] = &[
|
||||
"--gitlab-url",
|
||||
"--token-env-var",
|
||||
"--projects",
|
||||
"--default-project",
|
||||
],
|
||||
),
|
||||
("generate-docs", &["--full", "--project"]),
|
||||
|
||||
@@ -10,6 +10,7 @@ pub struct InitInputs {
|
||||
pub gitlab_url: String,
|
||||
pub token_env_var: String,
|
||||
pub project_paths: Vec<String>,
|
||||
pub default_project: Option<String>,
|
||||
}
|
||||
|
||||
pub struct InitOptions {
|
||||
@@ -23,6 +24,7 @@ pub struct InitResult {
|
||||
pub data_dir: String,
|
||||
pub user: UserInfo,
|
||||
pub projects: Vec<ProjectInfo>,
|
||||
pub default_project: Option<String>,
|
||||
}
|
||||
|
||||
pub struct UserInfo {
|
||||
@@ -104,6 +106,20 @@ pub async fn run_init(inputs: InitInputs, options: InitOptions) -> Result<InitRe
|
||||
));
|
||||
}
|
||||
|
||||
// Validate default_project matches one of the configured project paths
|
||||
if let Some(ref dp) = inputs.default_project {
|
||||
let matched = inputs.project_paths.iter().any(|p| {
|
||||
p.eq_ignore_ascii_case(dp)
|
||||
|| p.to_ascii_lowercase()
|
||||
.ends_with(&format!("/{}", dp.to_ascii_lowercase()))
|
||||
});
|
||||
if !matched {
|
||||
return Err(LoreError::Other(format!(
|
||||
"defaultProject '{dp}' does not match any configured project path"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(parent) = config_path.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
@@ -118,6 +134,7 @@ pub async fn run_init(inputs: InitInputs, options: InitOptions) -> Result<InitRe
|
||||
.iter()
|
||||
.map(|p| ProjectConfig { path: p.clone() })
|
||||
.collect(),
|
||||
default_project: inputs.default_project.clone(),
|
||||
};
|
||||
|
||||
let config_json = serde_json::to_string_pretty(&config)?;
|
||||
@@ -152,5 +169,6 @@ pub async fn run_init(inputs: InitInputs, options: InitOptions) -> Result<InitRe
|
||||
data_dir: data_dir.display().to_string(),
|
||||
user,
|
||||
projects: validated_projects.into_iter().map(|(p, _)| p).collect(),
|
||||
default_project: inputs.default_project,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -151,6 +151,10 @@ pub enum Commands {
|
||||
/// Comma-separated project paths (required in robot mode)
|
||||
#[arg(long)]
|
||||
projects: Option<String>,
|
||||
|
||||
/// Default project path (used when -p is omitted)
|
||||
#[arg(long)]
|
||||
default_project: Option<String>,
|
||||
},
|
||||
|
||||
#[command(hide = true)]
|
||||
|
||||
Reference in New Issue
Block a user