Enhance source command with enable/disable and improved list display#39
Enhance source command with enable/disable and improved list display#39
Conversation
- Add enabled/disabled field to UpstreamDef - Implement source enable/disable commands - Show last update time in source list - Add --check-remote flag to verify with remote registries - Display both remote and local registries in source list - Skip disabled sources during update and registry loading Co-authored-by: Yangmoooo <72434870+Yangmoooo@users.noreply.github.com>
|
@copilot 为什么这里在添加upstreamdef的enabled字段时,要单独设置一个函数?在default方法里指定还不够吗 |
这里需要单独定义 serde 反序列化时的字段缺失处理: 为什么不能用
这是 Rust serde 中处理"新增字段向后兼容"的标准模式。 |
There was a problem hiding this comment.
Pull request overview
Enhances the inro source command suite to support source enable/disable management and improves source list output to show both remote and local registries, including last-update times and optional remote update checks.
Changes:
- Add
source enable/source disablesubcommands and persist the enabled state in config. - Enhance
source listto display remote + local sources, last update time, and--check-remote. - Make registry loading respect the
enabledflag when merging upstream registry TOMLs.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/registry.rs |
Filters upstream registry merges to only enabled sources from config. |
src/config.rs |
Adds enabled: bool to UpstreamDef (with serde default) and updates defaults. |
src/commands/source.rs |
Implements improved source list, skips disabled sources on update, adds enable/disable logic, and remote update checking. |
src/cli.rs |
Extends CLI to accept source list --check-remote and new enable/disable subcommands. |
config.example.toml |
Updates example upstream definition to show enabled = false. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if !config_path.exists() { | ||
| return Err(anyhow!("Config file not found. Please run 'inro source update' first.")); | ||
| } |
| if *check_remote { | ||
| match check_remote_update(&upstream.url, &cached_path) { | ||
| Ok(true) => { | ||
| let s = format!("{} (update available)", time_str); | ||
| let d = s.as_str().yellow(); | ||
| (s, d) | ||
| } | ||
| Ok(false) => { | ||
| let s = format!("{} (up-to-date)", time_str); | ||
| let d = s.as_str().green(); | ||
| (s, d) | ||
| } | ||
| Err(_) => { | ||
| let s = format!("{} (check failed)", time_str); | ||
| let d = s.as_str().red(); | ||
| (s, d) | ||
| } | ||
| } | ||
| } else { | ||
| let d = time_str.as_str().normal(); | ||
| (time_str, d) | ||
| } |
| let enabled_names: HashSet<String> = config | ||
| .upstreams | ||
| .iter() | ||
| .filter(|u| u.enabled) | ||
| .map(|u| format!("{:02}-{}.toml", u.priority, u.name)) | ||
| .collect(); | ||
| let mut upstream_files = collect_toml_files(upstream_registry_dir)?; | ||
| upstream_files.retain(|p| { | ||
| p.file_name() | ||
| .and_then(|n| n.to_str()) | ||
| .map(|n| enabled_names.contains(n)) |
| #[serde(default = "default_enabled")] | ||
| pub enabled: bool, | ||
| } | ||
|
|
||
| fn default_enabled() -> bool { true } |
| @@ -173,7 +173,25 @@ pub enum SourceSubCommand { | |||
|
|
|||
| /// List all configured remote sources and their status | |||
source enable/disablecommandssource listdisplay (last update time, local + remote sources,--check-remoteflag)enabledfield toUpstreamDefin configenabledflag inRegistry::load()UpstreamDef.enabledfield - remove#[serde(default = "default_enabled")]and the helper function, use a plain field (per feedback: project is not stable yet, backward compat overhead not needed)Original prompt
sourcecommand #38✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.