feat(cli): add path & limit to session list command (#4878)

This commit is contained in:
Robert Mcgregor
2025-10-01 00:12:15 +10:00
committed by GitHub
parent 4d17c98334
commit 114a3b31cb
3 changed files with 38 additions and 16 deletions
+2 -2
View File
@@ -203,14 +203,14 @@ pub async fn handle_schedule_remove(id: String) -> Result<()> {
}
}
pub async fn handle_schedule_sessions(id: String, limit: Option<u32>) -> Result<()> {
pub async fn handle_schedule_sessions(id: String, limit: Option<usize>) -> Result<()> {
let scheduler_storage_path =
get_default_scheduler_storage_path().context("Failed to get scheduler storage path")?;
let scheduler = SchedulerFactory::create(scheduler_storage_path)
.await
.context("Failed to initialize scheduler")?;
match scheduler.sessions(&id, limit.unwrap_or(50) as usize).await {
match scheduler.sessions(&id, limit.unwrap_or(50)).await {
Ok(sessions) => {
if sessions.is_empty() {
println!("No sessions found for schedule ID '{}'.", id);
+22 -6
View File
@@ -114,14 +114,34 @@ pub async fn handle_session_remove(id: Option<String>, regex_string: Option<Stri
remove_sessions(matched_sessions).await
}
pub async fn handle_session_list(verbose: bool, format: String, ascending: bool) -> Result<()> {
pub async fn handle_session_list(
format: String,
ascending: bool,
working_dir: Option<PathBuf>,
limit: Option<usize>,
) -> Result<()> {
let mut sessions = SessionManager::list_sessions().await?;
if let Some(ref pat) = working_dir {
let pat_lower = pat.to_string_lossy().to_lowercase();
sessions.retain(|s| {
s.working_dir
.to_string_lossy()
.to_lowercase()
.contains(&pat_lower)
});
}
if ascending {
sessions.sort_by(|a, b| a.updated_at.cmp(&b.updated_at));
} else {
sessions.sort_by(|a, b| b.updated_at.cmp(&a.updated_at));
}
if let Some(n) = limit {
sessions.truncate(n);
}
match format.as_str() {
"json" => {
println!("{}", serde_json::to_string(&sessions)?);
@@ -138,11 +158,7 @@ pub async fn handle_session_list(verbose: bool, format: String, ascending: bool)
"{} - {} - {}",
session.id, session.description, session.updated_at
);
if verbose {
println!(" {}", output);
} else {
println!("{}", output);
}
println!("{}", output);
}
}
}