gusage 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +27 -18
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { execSync, spawn } from "child_process";
11
11
  // package.json
12
12
  var package_default = {
13
13
  name: "gusage",
14
- version: "1.2.0",
14
+ version: "1.2.1",
15
15
  description: "A standalone CLI to export Gemini CLI quota and usage statistics",
16
16
  module: "index.ts",
17
17
  type: "module",
@@ -136,6 +136,27 @@ function validateNotifyRuntime(notifyThreshold, isWatching, hasNotificationSuppo
136
136
  function shouldSendThresholdNotification(prevFraction, currentFraction, threshold) {
137
137
  return prevFraction !== undefined && prevFraction > threshold && currentFraction <= threshold;
138
138
  }
139
+ function parseWatchIntervalArg(raw) {
140
+ let totalMs = 0;
141
+ let found = false;
142
+ const normalizedParts = [];
143
+ const matches = raw.matchAll(/(\d+)(h|m|s)?/g);
144
+ for (const match of matches) {
145
+ found = true;
146
+ const val = parseInt(match[1], 10);
147
+ const unit = match[2] || "s";
148
+ normalizedParts.push(`${val}${unit}`);
149
+ if (unit === "s")
150
+ totalMs += val * 1000;
151
+ else if (unit === "m")
152
+ totalMs += val * 60000;
153
+ else if (unit === "h")
154
+ totalMs += val * 3600000;
155
+ }
156
+ if (!found)
157
+ return null;
158
+ return { intervalMs: totalMs, intervalStr: normalizedParts.join("") };
159
+ }
139
160
  function parseVersion(modelId) {
140
161
  const match = modelId.match(/gemini-(\d+)(?:\.(\d+))?-(.*)/);
141
162
  if (match) {
@@ -236,23 +257,10 @@ Options:
236
257
  let intervalMs = 1e4;
237
258
  let intervalStr = "10s";
238
259
  if (values.watch) {
239
- let totalMs = 0;
240
- const matches = values.watch.matchAll(/(\d+)(h|m|s)?/g);
241
- let found = false;
242
- for (const match of matches) {
243
- found = true;
244
- const val = parseInt(match[1], 10);
245
- const unit = match[2] || "s";
246
- if (unit === "s")
247
- totalMs += val * 1000;
248
- else if (unit === "m")
249
- totalMs += val * 60000;
250
- else if (unit === "h")
251
- totalMs += val * 3600000;
252
- }
253
- if (found) {
254
- intervalMs = totalMs;
255
- intervalStr = values.watch;
260
+ const parsedWatch = parseWatchIntervalArg(values.watch);
261
+ if (parsedWatch) {
262
+ intervalMs = parsedWatch.intervalMs;
263
+ intervalStr = parsedWatch.intervalStr;
256
264
  }
257
265
  }
258
266
  const useColor = !values["no-color"] && !process.env.NO_COLOR && process.stdout.isTTY;
@@ -511,6 +519,7 @@ async function refreshAccessToken(refreshToken) {
511
519
  export {
512
520
  validateNotifyRuntime,
513
521
  shouldSendThresholdNotification,
522
+ parseWatchIntervalArg,
514
523
  parseNotifyThresholdArg,
515
524
  main as default
516
525
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gusage",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A standalone CLI to export Gemini CLI quota and usage statistics",
5
5
  "module": "index.ts",
6
6
  "type": "module",