Skip to content

Commit

Permalink
factor out commands
Browse files Browse the repository at this point in the history
  • Loading branch information
richardjlyon committed May 30, 2023
1 parent 9d8cab6 commit 0c94cc1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/rust-ci.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/rust-ci.yml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# name: Rust CI

# on:
# push:
# branches:
# - main

# jobs:
# build:
# runs-on: macos-latest

# steps:
# - name: Set up Rust
# uses: actions/checkout@v2
# - name: Install cargo-audit
# run: cargo install cargo-audit
# - name: Build
# run: cargo build --verbose
# - name: Test
# run: cargo test --verbose
# - name: Clippy
# run: cargo clippy --verbose -- -D warnings
# - name: Audit
# run: cargo audit
8 changes: 3 additions & 5 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//! Transactionsa are stored in a database. Reports can be produced in [ledger](https://ledger-cli.org/features.html) format.
use clap::{Parser, Subcommand};
use money::commands::transactions::get_transactions;
use std::env;

use money::db;
use money::starling::client::{StarlingApiClient, StarlingClient};
use money::starling::client::StarlingApiClient;

/// Command line arguments
#[derive(Parser)]
Expand Down Expand Up @@ -51,9 +51,7 @@ async fn main() -> std::io::Result<()> {
Commands::Balances => todo!(),

Commands::Transactions { days } => {
if let Some(account) = client.accounts().await.iter().next() {
db::service::insert_or_update(&client, account, days).await;
}
get_transactions(&client, days);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod transactions;
13 changes: 13 additions & 0 deletions src/commands/transactions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Command Line Interface `Transaction` commands
use crate::{
db,
starling::client::{StarlingApiClient, StarlingClient},
};

/// Fetch transactions for the specified number of days and save to the database
pub async fn get_transactions(client: &StarlingApiClient, days: i64) {
if let Some(account) = client.accounts().await.iter().next() {
db::service::insert_or_update(client, account, days).await;
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod commands;
pub mod db;
pub mod entities;
pub mod starling;

0 comments on commit 0c94cc1

Please sign in to comment.