cli(command): Add export command to CLI for markdown export of sessions (#2533)

This commit is contained in:
Raduan Al-Shedivat
2025-06-04 23:27:21 +02:00
committed by GitHub
parent 465a43cf51
commit d3359a12a4
4 changed files with 1315 additions and 4 deletions
+31 -1
View File
@@ -34,7 +34,7 @@ struct Cli {
command: Option<Command>,
}
#[derive(Args)]
#[derive(Args, Debug)]
#[group(required = false, multiple = false)]
struct Identifier {
#[arg(
@@ -102,6 +102,19 @@ enum SessionCommand {
#[arg(short, long, help = "Regex for removing matched sessions (optional)")]
regex: Option<String>,
},
#[command(about = "Export a session to Markdown format")]
Export {
#[command(flatten)]
identifier: Option<Identifier>,
#[arg(
short,
long,
help = "Output file path (default: stdout)",
long_help = "Path to save the exported Markdown. If not provided, output will be sent to stdout"
)]
output: Option<PathBuf>,
},
}
#[derive(Subcommand, Debug)]
@@ -550,6 +563,23 @@ pub async fn cli() -> Result<()> {
handle_session_remove(id, regex)?;
return Ok(());
}
Some(SessionCommand::Export { identifier, output }) => {
let session_identifier = if let Some(id) = identifier {
extract_identifier(id)
} else {
// If no identifier is provided, prompt for interactive selection
match crate::commands::session::prompt_interactive_session_selection() {
Ok(id) => id,
Err(e) => {
eprintln!("Error: {}", e);
return Ok(());
}
}
};
crate::commands::session::handle_session_export(session_identifier, output)?;
Ok(())
}
None => {
// Run session command by default
let mut session: crate::Session = build_session(SessionBuilderConfig {