From 5bccdc933a0f6fb6fd9f8498fca9cf90fef4ded5 Mon Sep 17 00:00:00 2001 From: Bellabuks Date: Fri, 29 May 2026 22:49:32 +0100 Subject: [PATCH] feat(devkit/cli): add --output flag to export subcommand --- packages/devkit/src/cli/export.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/devkit/src/cli/export.rs b/packages/devkit/src/cli/export.rs index 4454a41..9a7c474 100644 --- a/packages/devkit/src/cli/export.rs +++ b/packages/devkit/src/cli/export.rs @@ -1,11 +1,31 @@ -use crate::simulation::fee_model::FeePoint; use std::fmt::Write as FmtWrite; +use std::path::{Path, PathBuf}; + +use crate::simulation::fee_model::FeePoint; + +/// Arguments for the `export` subcommand. +pub struct ExportArgs { + /// Source SQLite database path. + pub db: PathBuf, + /// Output file path. Writes to stdout when `None`. + pub output: Option, +} + +impl ExportArgs { + /// Run the export, writing CSV to file or stdout. + pub fn run(&self, points: &[FeePoint]) { + match &self.output { + Some(path) => Export::write_csv(points, path).expect("failed to write output"), + None => print!("{}", Export::to_csv(points)), + } + } +} /// Exports devkit results to external formats. pub struct Export; impl Export { - /// Serialize fee points to CSV string with columns: timestamp,fee,ledger,is_spike. + /// Serialize fee points to CSV. pub fn to_csv(points: &[FeePoint]) -> String { let mut out = String::from("timestamp,fee,ledger,is_spike\n"); for p in points { @@ -15,7 +35,7 @@ impl Export { } /// Write fee points to a CSV file. - pub fn write_csv(points: &[FeePoint], path: &std::path::Path) -> std::io::Result<()> { + pub fn write_csv(points: &[FeePoint], path: &Path) -> std::io::Result<()> { std::fs::write(path, Self::to_csv(points)) } }