feat(cli)!: convert update subcommand to --update flag

BREAKING CHANGE: The 'update' subcommand is replaced with flags:
- Use '--update' to update all cached repositories
- Use '--update --repo owner/repo' to update a specific repo
- Searching for 'update' keyword now works: 'gh-celebs update'
This commit is contained in:
2026-03-23 17:57:42 +02:00
parent 23775e3c67
commit 5f645f884d
2 changed files with 34 additions and 42 deletions

View File

@@ -1,13 +1,10 @@
use clap::{Parser, Subcommand}; use clap::Parser;
#[derive(Parser)] #[derive(Parser)]
#[command(name = "gh-celebs")] #[command(name = "gh-celebs")]
#[command(about = "A fast CLI tool for searching GitHub repositories by popularity")] #[command(about = "A fast CLI tool for searching GitHub repositories by popularity")]
#[command(version)] #[command(version)]
pub struct Cli { pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
#[arg(help = "Search query", value_name = "QUERY")] #[arg(help = "Search query", value_name = "QUERY")]
pub query: Option<String>, pub query: Option<String>,
@@ -16,15 +13,13 @@ pub struct Cli {
#[arg(long, help = "Output results as JSON")] #[arg(long, help = "Output results as JSON")]
pub json: bool, pub json: bool,
}
#[derive(Subcommand)] #[arg(long, help = "Update cached repositories")]
pub enum Commands { pub update: bool,
#[command(about = "Update cached repositories")]
Update { #[arg(
#[arg( long,
help = "Repository to update (format: owner/repo). If not specified, updates all cached repos." help = "Repository to update (format: owner/repo). Requires --update"
)] )]
repo: Option<String>, pub repo: Option<String>,
},
} }

View File

@@ -11,7 +11,7 @@ use clap::Parser;
use directories::ProjectDirs; use directories::ProjectDirs;
use std::path::PathBuf; use std::path::PathBuf;
use crate::cli::{Cli, Commands}; use crate::cli::Cli;
use crate::config::Config; use crate::config::Config;
use crate::db::Database; use crate::db::Database;
use crate::github::GitHubClient; use crate::github::GitHubClient;
@@ -51,38 +51,35 @@ async fn main() -> Result<()> {
let github = GitHubClient::new(config.github.token)?; let github = GitHubClient::new(config.github.token)?;
let search_engine = SearchEngine::new(db, github); let search_engine = SearchEngine::new(db, github);
match cli.command { if cli.update {
Some(Commands::Update { repo }) => { if let Some(repo_name) = cli.repo {
if let Some(repo_name) = repo { let rate_limit = search_engine.update_single(&repo_name).await?;
let rate_limit = search_engine.update_single(&repo_name).await?; if rate_limit.remaining < 3 {
if rate_limit.remaining < 3 { eprintln!("Warning: Rate limit running low ({} remaining)", rate_limit.remaining);
eprintln!("Warning: Rate limit running low ({} remaining)", rate_limit.remaining); }
} } else {
} else { let rate_limit = search_engine.update_all().await?;
let rate_limit = search_engine.update_all().await?; if rate_limit.remaining < 3 {
if rate_limit.remaining < 3 { eprintln!("Warning: Rate limit running low ({} remaining)", rate_limit.remaining);
eprintln!("Warning: Rate limit running low ({} remaining)", rate_limit.remaining);
}
} }
} }
None => { } else {
let query = cli.query.ok_or_else(|| { let query = cli.query.ok_or_else(|| {
anyhow::anyhow!("Query is required when not using a subcommand") anyhow::anyhow!("Query is required. Use --update to update cached repositories.")
})?; })?;
let response = search_engine.search(&query, cli.limit).await?; let response = search_engine.search(&query, cli.limit).await?;
if cli.json { if cli.json {
let json = OutputFormatter::format_json(&response)?; let json = OutputFormatter::format_json(&response)?;
println!("{}", json); println!("{}", json);
} else { } else {
let text = OutputFormatter::format_text(&response)?; let text = OutputFormatter::format_text(&response)?;
println!("{}", text); println!("{}", text);
} }
if response.api_remaining < 3 { if response.api_remaining < 3 {
eprintln!("Warning: GitHub API rate limit running low ({} remaining)", response.api_remaining); eprintln!("Warning: GitHub API rate limit running low ({} remaining)", response.api_remaining);
}
} }
} }