feat(cli): add path & limit to session list command (#4878)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user