diff --git a/src/cli.rs b/src/cli.rs index 430093b..7b68996 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,3 +1,5 @@ +pub mod export; + use std::{net::SocketAddr, path::PathBuf}; use clap::{Args, Parser, Subcommand}; @@ -20,8 +22,8 @@ pub enum Command { /// Run the web application. Web(WebArgs), - /// List all the votes in JSONL format. - ListVotes(ListVotesArgs), + /// Export all the votes in JSONL format. + ExportVotes(ExportVotes), } #[derive(Args)] @@ -78,7 +80,7 @@ impl DbArgs { } #[derive(Args)] -pub struct ListVotesArgs { +pub struct ExportVotes { #[clap(flatten)] pub db: DbArgs, } diff --git a/src/cli/export.rs b/src/cli/export.rs new file mode 100644 index 0000000..4ddf51f --- /dev/null +++ b/src/cli/export.rs @@ -0,0 +1,12 @@ +use serde_json::json; + +use crate::{cli::ExportVotes, prelude::*}; + +pub async fn export_votes(args: ExportVotes) -> Result { + let manager = args.db.open()?.vote_manager()?; + for result in manager.iter_all() { + let (account_id, tank_id, vote) = result?; + println!("{}", json!({ "account_id": account_id, "tank_id": tank_id, "vote": vote })); + } + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index c168caa..6dfcba6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,10 +18,9 @@ mod web; mod weegee; use clap::Parser; -use serde_json::json; use crate::{ - cli::{Cli, Command, ListVotesArgs}, + cli::{Cli, Command}, prelude::*, tracing::trace, }; @@ -33,15 +32,6 @@ async fn main() -> Result { match args.command { Command::Web(args) => trace(web::run(args).await), - Command::ListVotes(args) => trace(list_votes(args).await), + Command::ExportVotes(args) => trace(cli::export::export_votes(args).await), } } - -async fn list_votes(args: ListVotesArgs) -> Result { - let manager = args.db.open()?.vote_manager()?; - for result in manager.iter_all() { - let (account_id, tank_id, vote) = result?; - println!("{}", json!({ "account_id": account_id, "tank_id": tank_id, "vote": vote })); - } - Ok(()) -}