Add support for ascending/descending ordering of goose session list (#2087)

This commit is contained in:
Raduan Al-Shedivat
2025-04-23 17:21:27 +02:00
committed by GitHub
parent ab5447057e
commit 08682507d9
4 changed files with 54 additions and 11 deletions
+13 -2
View File
@@ -73,6 +73,13 @@ enum SessionCommand {
default_value = "text"
)]
format: String,
#[arg(
long = "ascending",
help = "Sort by date in ascending order (oldest first)",
long_help = "Sort sessions by date in ascending order (oldest first). Default is descending order (newest first)."
)]
ascending: bool,
},
#[command(about = "Remove sessions")]
Remove {
@@ -393,8 +400,12 @@ pub async fn cli() -> Result<()> {
builtins,
}) => {
return match command {
Some(SessionCommand::List { verbose, format }) => {
handle_session_list(verbose, format)?;
Some(SessionCommand::List {
verbose,
format,
ascending,
}) => {
handle_session_list(verbose, format, ascending)?;
Ok(())
}
Some(SessionCommand::Remove { id, regex }) => {
+10 -4
View File
@@ -1,5 +1,5 @@
use anyhow::{Context, Result};
use goose::session::info::{get_session_info, SessionInfo};
use goose::session::info::{get_session_info, SessionInfo, SortOrder};
use regex::Regex;
use std::fs;
@@ -21,7 +21,7 @@ pub fn remove_session(session: &SessionInfo) -> Result<()> {
}
pub fn handle_session_remove(id: String, regex_string: String) -> Result<()> {
let sessions = match get_session_info() {
let sessions = match get_session_info(SortOrder::Descending) {
Ok(sessions) => sessions,
Err(e) => {
tracing::error!("Failed to remove sessions: {:?}", e);
@@ -57,8 +57,14 @@ pub fn handle_session_remove(id: String, regex_string: String) -> Result<()> {
Ok(())
}
pub fn handle_session_list(verbose: bool, format: String) -> Result<()> {
let sessions = match get_session_info() {
pub fn handle_session_list(verbose: bool, format: String, ascending: bool) -> Result<()> {
let sort_order = if ascending {
SortOrder::Ascending
} else {
SortOrder::Descending
};
let sessions = match get_session_info(sort_order) {
Ok(sessions) => sessions,
Err(e) => {
tracing::error!("Failed to list sessions: {:?}", e);