Skip to content

Commit

Permalink
Add --begin arguments to account activity get sub-command
Browse files Browse the repository at this point in the history
The account activity get sub-command currently unconditionally lists all
the account activities available. This can be somewhat unwieldy for
accounts that have been open for a while or have a lot of transactions.
To give the user a bit more control over what to display, this change
adds the --begin argument to said sub-command to specify the start date
at which to begin listing activities.
  • Loading branch information
d-e-s-o committed Dec 1, 2023
1 parent 84d5c88 commit 9480d5c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
----------
- Added support for "journal entry" type account activities
- Introduced `--begin` argument to `activity get` sub-command
- Bumped minimum supported Rust version to `1.63`
- Bumped `apca` dependency to `0.28.0`

Expand Down
10 changes: 9 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ pub enum Account {
pub enum Activity {
/// Retrieve account activity.
#[clap(arg_enum)]
Get,
Get(ActivityGet),
}

#[derive(Debug, ClapArgs)]
pub struct ActivityGet {
/// Only show activities dated at the given date or after (format:
/// yyyy-mm-dd).
#[clap(short, long)]
pub begin: Option<NaiveDate>,
}

/// An enumeration representing the `account config` sub command.
Expand Down
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ use yansi::Paint;

use crate::args::Account;
use crate::args::Activity;
use crate::args::ActivityGet;
use crate::args::Args;
use crate::args::Asset;
use crate::args::AssetClass;
Expand Down Expand Up @@ -198,7 +199,7 @@ async fn account_get(client: Client) -> Result<()> {
/// The handler for the 'account activity' command.
async fn account_activity(client: Client, activity: Activity) -> Result<()> {
match activity {
Activity::Get => account_activity_get(client).await,
Activity::Get(get) => account_activity_get(client, get).await,
}
}

Expand Down Expand Up @@ -275,8 +276,14 @@ fn sort_account_activity(activities: &mut [account_activities::Activity]) {


/// Retrieve account activity.
async fn account_activity_get(client: Client) -> Result<()> {
let request = account_activities::ActivityReq::default();
async fn account_activity_get(client: Client, get: ActivityGet) -> Result<()> {
let request = account_activities::ActivityReq {
after: get
.begin
.map(|begin| Utc.from_utc_datetime(&begin.and_hms_opt(0, 0, 0).unwrap())),
..Default::default()
};

let currency = client.issue::<account::Get>(&());
let activity = client.issue::<account_activities::Get>(&request);

Expand Down

0 comments on commit 9480d5c

Please sign in to comment.