Skip to content

Commit fe43be4

Browse files
committed
fix(ci): satisfy rustfmt and clippy
1 parent bf86e53 commit fe43be4

16 files changed

Lines changed: 463 additions & 369 deletions

src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use anyhow::Result;
4343

4444
use crate::cli;
4545
use crate::pipeline;
46-
use crate::types::{DailyReport, UsageEvent, ParseStats};
46+
use crate::types::{DailyReport, ParseStats, UsageEvent};
4747

4848
/// Configuration for token usage analysis.
4949
///

src/cli.rs

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,55 +70,114 @@ pub enum CostSource {
7070
#[cfg_attr(feature = "cli", derive(Args))]
7171
#[derive(Debug, Clone, Default)]
7272
pub struct CommonArgs {
73-
#[cfg_attr(feature = "cli", arg(long, short = 's', help = "Start date filter (YYYYMMDD or YYYY-MM-DD)"))]
73+
#[cfg_attr(
74+
feature = "cli",
75+
arg(long, short = 's', help = "Start date filter (YYYYMMDD or YYYY-MM-DD)")
76+
)]
7477
pub since: Option<String>,
75-
#[cfg_attr(feature = "cli", arg(long, short = 'u', help = "End date filter (YYYYMMDD or YYYY-MM-DD)"))]
78+
#[cfg_attr(
79+
feature = "cli",
80+
arg(long, short = 'u', help = "End date filter (YYYYMMDD or YYYY-MM-DD)")
81+
)]
7682
pub until: Option<String>,
7783
#[cfg_attr(feature = "cli", arg(long, short = 'j', help = "Output JSON report"))]
7884
pub json: bool,
79-
#[cfg_attr(feature = "cli", arg(long, short = 'q', help = "Process JSON output with jq expression (implies --json)"))]
85+
#[cfg_attr(
86+
feature = "cli",
87+
arg(
88+
long,
89+
short = 'q',
90+
help = "Process JSON output with jq expression (implies --json)"
91+
)
92+
)]
8093
pub jq: Option<String>,
8194
#[cfg_attr(feature = "cli", arg(long, short = 'd', help = "Show debug summary"))]
8295
pub debug: bool,
83-
#[cfg_attr(feature = "cli", arg(long, default_value_t = 5, help = "Debug sample count"))]
96+
#[cfg_attr(
97+
feature = "cli",
98+
arg(long, default_value_t = 5, help = "Debug sample count")
99+
)]
84100
pub debug_samples: usize,
85101
#[cfg_attr(feature = "cli", arg(long, short = 'o', value_enum, default_value_t = SortOrder::Asc))]
86102
pub order: SortOrder,
87-
#[cfg_attr(feature = "cli", arg(long, short = 'b', help = "Show per-model breakdown"))]
103+
#[cfg_attr(
104+
feature = "cli",
105+
arg(long, short = 'b', help = "Show per-model breakdown")
106+
)]
88107
pub breakdown: bool,
89-
#[cfg_attr(feature = "cli", arg(long, short = 'O', help = "Use offline pricing behavior"))]
108+
#[cfg_attr(
109+
feature = "cli",
110+
arg(long, short = 'O', help = "Use offline pricing behavior")
111+
)]
90112
pub offline: bool,
91-
#[cfg_attr(feature = "cli", arg(long, short = 'z', help = "Timezone for date grouping (e.g. UTC, Asia/Tokyo)"))]
113+
#[cfg_attr(
114+
feature = "cli",
115+
arg(
116+
long,
117+
short = 'z',
118+
help = "Timezone for date grouping (e.g. UTC, Asia/Tokyo)"
119+
)
120+
)]
92121
pub timezone: Option<String>,
93-
#[cfg_attr(feature = "cli", arg(long, short = 'l', help = "Locale for date/time formatting"))]
122+
#[cfg_attr(
123+
feature = "cli",
124+
arg(long, short = 'l', help = "Locale for date/time formatting")
125+
)]
94126
pub locale: Option<String>,
95127
#[cfg_attr(feature = "cli", arg(long, help = "Path to config JSON"))]
96128
pub config: Option<String>,
97129
#[cfg_attr(feature = "cli", arg(long, help = "Force compact table mode"))]
98130
pub compact: bool,
99-
#[cfg_attr(feature = "cli", arg(long, help = "Worker thread count (default: CPU cores)"))]
131+
#[cfg_attr(
132+
feature = "cli",
133+
arg(long, help = "Worker thread count (default: CPU cores)")
134+
)]
100135
pub workers: Option<usize>,
101136
#[cfg_attr(feature = "cli", arg(long, help = "Disable Claude source"))]
102137
pub no_claude: bool,
103138
#[cfg_attr(feature = "cli", arg(long, help = "Disable Codex source"))]
104139
pub no_codex: bool,
105140
#[cfg_attr(feature = "cli", arg(long, help = "Disable Antigravity quota probe"))]
106141
pub no_antigravity: bool,
107-
#[cfg_attr(feature = "cli", arg(long = "claude-projects-dir", help = "Claude projects dir, repeatable"))]
142+
#[cfg_attr(
143+
feature = "cli",
144+
arg(long = "claude-projects-dir", help = "Claude projects dir, repeatable")
145+
)]
108146
pub claude_projects_dir: Vec<String>,
109-
#[cfg_attr(feature = "cli", arg(long = "codex-sessions-dir", help = "Codex sessions dir, repeatable"))]
147+
#[cfg_attr(
148+
feature = "cli",
149+
arg(long = "codex-sessions-dir", help = "Codex sessions dir, repeatable")
150+
)]
110151
pub codex_sessions_dir: Vec<String>,
111-
#[cfg_attr(feature = "cli", arg(long = "ignore-path", help = "Ignore paths containing this substring (repeatable)"))]
152+
#[cfg_attr(
153+
feature = "cli",
154+
arg(
155+
long = "ignore-path",
156+
help = "Ignore paths containing this substring (repeatable)"
157+
)
158+
)]
112159
pub ignore_path: Vec<String>,
113-
#[cfg_attr(feature = "cli", arg(long, help = "Disable built-in heavy directory ignore list"))]
160+
#[cfg_attr(
161+
feature = "cli",
162+
arg(long, help = "Disable built-in heavy directory ignore list")
163+
)]
114164
pub no_default_ignores: bool,
115165
#[cfg_attr(feature = "cli", arg(long, help = "Disable incremental parse cache"))]
116166
pub no_incremental_cache: bool,
117-
#[cfg_attr(feature = "cli", arg(long, help = "Rebuild incremental parse cache from scratch"))]
167+
#[cfg_attr(
168+
feature = "cli",
169+
arg(long, help = "Rebuild incremental parse cache from scratch")
170+
)]
118171
pub rebuild_cache: bool,
119-
#[cfg_attr(feature = "cli", arg(long, help = "Optional pricing override JSON file"))]
172+
#[cfg_attr(
173+
feature = "cli",
174+
arg(long, help = "Optional pricing override JSON file")
175+
)]
120176
pub pricing_file: Option<String>,
121-
#[cfg_attr(feature = "cli", arg(long, help = "Enrich reports with locally inferred coding activity"))]
177+
#[cfg_attr(
178+
feature = "cli",
179+
arg(long, help = "Enrich reports with locally inferred coding activity")
180+
)]
122181
pub with_activity: bool,
123182
#[cfg_attr(feature = "cli", arg(long = "slow", short = 'S', num_args = 0..=1, default_missing_value = "60", help = "Slow output for long content (optional: ms per line, default 30)"))]
124183
pub slow: Option<u64>,

src/heartbeat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ use anyhow::{Context, Result, bail};
99
use chrono::{DateTime, Local, NaiveDate, TimeDelta, Utc};
1010
use serde::{Deserialize, Serialize};
1111

12-
#[cfg(feature = "cli")]
13-
use std::io::IsTerminal;
14-
#[cfg(feature = "cli")]
15-
use std::process::{Command, Stdio};
1612
#[cfg(feature = "cli")]
1713
use comfy_table::{
1814
Attribute, Cell as TableCell, Color as TableColor, ContentArrangement, Row as TableRow,
1915
Table as TextTable, modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL,
2016
};
2117
#[cfg(feature = "cli")]
2218
use notify::{Config, Event, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
19+
#[cfg(feature = "cli")]
20+
use std::io::IsTerminal;
21+
#[cfg(feature = "cli")]
22+
use std::process::{Command, Stdio};
2323

2424
#[cfg(feature = "cli")]
2525
use crate::activity::{dataset_from_heartbeats, format_activity_duration};

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,25 @@ mod types;
128128
// ---------------------------------------------------------------------------
129129

130130
pub use api::{Config, SortOrder, WeekStart};
131-
pub use api::{daily_report, daily_report_with_week_start, load_events, parse_stats, usage_snapshot};
131+
pub use api::{
132+
daily_report, daily_report_with_week_start, load_events, parse_stats, usage_snapshot,
133+
};
132134
pub use pipeline::{ReportPeriod, TimeZoneMode, UsageSnapshot};
133135
pub use types::{
134-
ActivitySummary, DailyReport, DailyRow, DateFilter, ParseStats,
135-
PricingRate, PricingTable, SourceKind, TokenCounts, UsageAccumulator, UsageEvent,
136+
ActivitySummary, DailyReport, DailyRow, DateFilter, ParseStats, PricingRate, PricingTable,
137+
SourceKind, TokenCounts, UsageAccumulator, UsageEvent,
136138
};
137139

138140
// ---------------------------------------------------------------------------
139141
// CLI entry point — only available with `cli` feature
140142
// ---------------------------------------------------------------------------
141143

144+
#[cfg(feature = "cli")]
145+
use crate::cli::{Cli, Commands, DailyArgs, normalize_cli_args};
142146
#[cfg(feature = "cli")]
143147
use anyhow::Result;
144148
#[cfg(feature = "cli")]
145149
use clap::Parser;
146-
#[cfg(feature = "cli")]
147-
use crate::cli::{Cli, Commands, DailyArgs, normalize_cli_args};
148150

149151
/// Run the CLI application.
150152
///

src/pipeline/activity_report.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::activity::{
1717
use crate::cli::CommonArgs;
1818
use crate::types::{ActivitySummary, SourceKind, TokenCounts, UsageEvent};
1919

20-
use super::*;
2120
use super::display::*;
21+
use super::*;
2222

2323
#[derive(Debug, Clone, Serialize)]
2424
pub(super) struct ActivityOverview {
@@ -93,7 +93,6 @@ pub(super) struct ActivityOut {
9393
pub(super) stats: ParseStats,
9494
}
9595

96-
9796
pub(super) fn apply_default_activity_range(
9897
common: &mut CommonArgs,
9998
tz: &TimeZoneMode,
@@ -303,7 +302,10 @@ pub(super) fn build_activity_overview(
303302
}
304303
}
305304

306-
pub(super) fn activity_rate(activity: Option<&ActivitySummary>, totals: &TokenCounts) -> Option<(u64, f64)> {
305+
pub(super) fn activity_rate(
306+
activity: Option<&ActivitySummary>,
307+
totals: &TokenCounts,
308+
) -> Option<(u64, f64)> {
307309
let summary = activity?;
308310
if summary.total_seconds == 0 {
309311
return None;
@@ -318,7 +320,10 @@ pub(super) fn activity_rate(activity: Option<&ActivitySummary>, totals: &TokenCo
318320
))
319321
}
320322

321-
pub(super) fn token_breakdowns_by_model(events: &[UsageEvent], limit: usize) -> Vec<TokenBreakdownStat> {
323+
pub(super) fn token_breakdowns_by_model(
324+
events: &[UsageEvent],
325+
limit: usize,
326+
) -> Vec<TokenBreakdownStat> {
322327
let mut totals = HashMap::<String, TokenCounts>::new();
323328
let mut grand_total = 0u64;
324329

@@ -354,15 +359,21 @@ pub(super) fn token_breakdowns_by_model(events: &[UsageEvent], limit: usize) ->
354359
.collect()
355360
}
356361

357-
pub(super) fn aggregate_usage_totals_by_project(events: &[UsageEvent]) -> HashMap<String, TokenCounts> {
362+
pub(super) fn aggregate_usage_totals_by_project(
363+
events: &[UsageEvent],
364+
) -> HashMap<String, TokenCounts> {
358365
aggregate_usage_totals_by(events, |event| Some(project_label_for_activity(event)))
359366
}
360367

361-
pub(super) fn aggregate_usage_totals_by_language(_events: &[UsageEvent]) -> HashMap<String, TokenCounts> {
368+
pub(super) fn aggregate_usage_totals_by_language(
369+
_events: &[UsageEvent],
370+
) -> HashMap<String, TokenCounts> {
362371
HashMap::new()
363372
}
364373

365-
pub(super) fn aggregate_usage_totals_by_source(events: &[UsageEvent]) -> HashMap<String, TokenCounts> {
374+
pub(super) fn aggregate_usage_totals_by_source(
375+
events: &[UsageEvent],
376+
) -> HashMap<String, TokenCounts> {
366377
aggregate_usage_totals_by(events, |event| {
367378
Some(activity_source_label(event.source).to_string())
368379
})
@@ -904,4 +915,3 @@ pub(super) fn print_source_model_breakdown_section(
904915
print_activity_breakdown_section("Sources", sources);
905916
print_token_breakdown_section("Models", models);
906917
}
907-

src/pipeline/commands.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,24 @@ use anyhow::{Context, Result, bail};
44
use chrono::Utc;
55
use serde::Serialize;
66

7-
use crate::activity::{
8-
ActivityDataset, activity_enabled, fetch_activity_dataset,
9-
};
10-
use crate::cli::{CommonArgs, SortOrder};
7+
use crate::activity::{ActivityDataset, activity_enabled, fetch_activity_dataset};
118
#[cfg(feature = "cli")]
129
use crate::cli::{
13-
ActivityArgs, AntigravityArgs, DailyArgs, MonthlyArgs, SessionArgs,
14-
TodayArgs, WeeklyArgs,
10+
ActivityArgs, AntigravityArgs, DailyArgs, MonthlyArgs, SessionArgs, TodayArgs, WeeklyArgs,
1511
};
12+
use crate::cli::{CommonArgs, SortOrder};
1613
#[cfg(feature = "cli")]
1714
use crate::output::{print_report_table_with_options, run_report_tui};
18-
use crate::types::{
19-
ActivitySummary, DailyReport, DailyRow, ParseStats, TokenCounts, UsageEvent,
20-
};
15+
use crate::types::{ActivitySummary, DailyReport, DailyRow, ParseStats, TokenCounts, UsageEvent};
2116

22-
use super::*;
2317
#[cfg(feature = "cli")]
2418
use super::activity_report::*;
2519
#[cfg(feature = "cli")]
2620
use super::official::{fetch_antigravity_official_limits, select_antigravity_models};
2721
use super::parsing::load_usage;
2822
#[cfg(feature = "cli")]
2923
use super::statusline::{format_reset_timestamp, format_time_until_reset_short};
24+
use super::*;
3025

3126
pub(super) async fn enrich_rows_with_activity(
3227
common: &CommonArgs,
@@ -55,7 +50,10 @@ pub(super) async fn enrich_rows_with_activity(
5550
Ok((rows, totals))
5651
}
5752

58-
pub(super) fn report_date_bounds(events: &[UsageEvent], tz: &TimeZoneMode) -> Option<(NaiveDate, NaiveDate)> {
53+
pub(super) fn report_date_bounds(
54+
events: &[UsageEvent],
55+
tz: &TimeZoneMode,
56+
) -> Option<(NaiveDate, NaiveDate)> {
5957
let mut min_day: Option<NaiveDate> = None;
6058
let mut max_day: Option<NaiveDate> = None;
6159

@@ -291,7 +289,6 @@ pub(crate) async fn run_weekly(args: WeeklyArgs) -> Result<()> {
291289
}
292290
}
293291

294-
295292
#[cfg(feature = "cli")]
296293
pub(crate) async fn run_today(mut args: TodayArgs) -> Result<()> {
297294
let tz = parse_timezone_mode(args.common.timezone.as_deref())?;
@@ -435,7 +432,6 @@ pub(crate) async fn run_activity(mut args: ActivityArgs) -> Result<()> {
435432
}
436433
}
437434

438-
439435
#[cfg(feature = "cli")]
440436
pub(crate) async fn run_antigravity(args: AntigravityArgs) -> Result<()> {
441437
let tz = parse_timezone_mode(args.timezone.as_deref())?;
@@ -618,7 +614,6 @@ pub(crate) async fn run_session(args: SessionArgs) -> Result<()> {
618614
// tu top — real-time per-session token process viewer (htop for tokens)
619615
// ---------------------------------------------------------------------------
620616

621-
622617
pub async fn collect_report(
623618
common: CommonArgs,
624619
period: ReportPeriod,

src/pipeline/display.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use std::io::IsTerminal;
22

33
use comfy_table::{
4-
Attribute, Cell as TableCell, Color as TableColor, ContentArrangement,
5-
Table as TextTable, modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL,
4+
Attribute, Cell as TableCell, Color as TableColor, ContentArrangement, Table as TextTable,
5+
modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL,
66
};
77
use terminal_size::{Width, terminal_size};
88

9-
10-
use super::*;
119
use super::activity_report::ActivityOverview;
10+
use super::*;
1211

1312
pub(super) fn use_styled_output() -> bool {
1413
std::io::stdout().is_terminal() || std::env::var("CLICOLOR_FORCE").is_ok()
@@ -245,4 +244,3 @@ pub(super) fn shorten_model_name(model: &str) -> String {
245244
.replace("-20250131", "");
246245
if s.len() > 16 { s[..16].to_string() } else { s }
247246
}
248-

src/pipeline/live.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ use ratatui::style::{Color as TuiColor, Modifier, Style};
1515
use ratatui::text::{Line, Span};
1616
use ratatui::widgets::{Gauge, Paragraph, Wrap};
1717

18-
use crate::activity::{activity_enabled, fetch_activity_dataset, ActivityDataset};
18+
use crate::activity::{ActivityDataset, activity_enabled, fetch_activity_dataset};
1919
use crate::cli::{BlocksArgs, CommonArgs};
2020
use crate::types::{ActivitySummary, SourceKind, TokenCounts, UsageEvent};
2121

22-
use super::*;
2322
use super::block_report::build_block_json_report;
2423
use super::membership::*;
2524
use super::official::*;
2625
use super::parsing::load_usage;
2726
use super::statusline::*;
27+
use super::*;
2828

2929
pub(crate) async fn run_blocks(args: BlocksArgs) -> Result<()> {
3030
if args.session_length == 0 {
@@ -1882,7 +1882,10 @@ pub(super) fn live_key_value_line(
18821882
])
18831883
}
18841884

1885-
pub(super) fn activity_hourly_values(summary: &ActivitySummary, totals: &TokenCounts) -> Option<(u64, f64)> {
1885+
pub(super) fn activity_hourly_values(
1886+
summary: &ActivitySummary,
1887+
totals: &TokenCounts,
1888+
) -> Option<(u64, f64)> {
18861889
if summary.total_seconds == 0 {
18871890
return None;
18881891
}

0 commit comments

Comments
 (0)