diff --git a/crates/pollard-cli/src/main.rs b/crates/pollard-cli/src/main.rs index 4e620da4..4ea143a8 100644 --- a/crates/pollard-cli/src/main.rs +++ b/crates/pollard-cli/src/main.rs @@ -81,6 +81,7 @@ enum Command { #[command(subcommand)] action: StepAction, }, + DumpSession, } #[derive(Debug, Subcommand)] @@ -275,6 +276,10 @@ fn main() { let (actions, report) = steps::cleanup::run(&session); (actions, vec![Box::new(report)]) } + Command::DumpSession => { + let report = session::SessionReport::new(&session); + (vec![], vec![Box::new(report)]) + } }; render_and_apply(actions, reports, &session); diff --git a/crates/pollard-cli/src/session.rs b/crates/pollard-cli/src/session.rs index 1be9383c..8a0c2b5a 100644 --- a/crates/pollard-cli/src/session.rs +++ b/crates/pollard-cli/src/session.rs @@ -3,12 +3,43 @@ use std::path::PathBuf; use pollard_core::config::{Commands, Config, LanguageId, Ordering, Vcs}; use serde::Serialize; -use crate::io::{DiffStyle, Style}; +use crate::io::{DiffStyle, Report, Style, hashed_path}; use crate::Cli; +pub struct SessionReport { + json: String, + debug: String, +} + +impl SessionReport { + pub fn new(session: &Session) -> Self { + Self { + json: serde_json::to_string_pretty(session).expect("failed to serialize"), + debug: format!("{session:#?}"), + } + } +} + +impl Report for SessionReport { + fn get_dir(&self, session: &Session) -> PathBuf { + session.report_dir.join("session") + } + + fn make_path(&self, session: &Session) -> PathBuf { + hashed_path(&self.get_dir(session), &self.json, "session") + } + + fn render(&self, style: &Style, _no_color: bool, _depth: u8) { + match style { + Style::Json => println!("{}", self.json), + _ => println!("{}", self.debug), + } + } +} + // All fields are resolved and non-optional. No defaults are applied here; // every value must be provided by CLI args or config. No Option types allowed. -#[derive(Serialize)] +#[derive(Debug, Serialize)] pub struct Session { pub language: LanguageId, pub vcs: Vcs,