@aiusage/cli 1.4.1 → 1.4.3
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.
- package/dist/cli.js +65 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require < "u" ? require : typeof
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
// src/cli.ts
|
|
10
|
-
import { existsSync as existsSync2 } from "node:fs";
|
|
11
10
|
import { createInterface as createInterface3 } from "node:readline";
|
|
12
11
|
import { hostname as hostname3 } from "node:os";
|
|
13
12
|
|
|
@@ -2661,9 +2660,10 @@ try {
|
|
|
2661
2660
|
console.log(`To deploy the server, clone the repo and run the setup wizard:
|
|
2662
2661
|
`), console.log(" git clone https://github.com/ennann/aiusage.git"), console.log(" cd aiusage && pnpm install"), console.log(` pnpm setup
|
|
2663
2662
|
`), console.log("See: https://github.com/ennann/aiusage#deploy-your-own-server");
|
|
2664
|
-
else if (command === "--help" || command === "-h" || command === "help")
|
|
2665
|
-
|
|
2666
|
-
|
|
2663
|
+
else if (command === "--help" || command === "-h" || command === "help") {
|
|
2664
|
+
let zh2 = (await readConfig()).lang === "zh";
|
|
2665
|
+
printHelp(zh2);
|
|
2666
|
+
} else {
|
|
2667
2667
|
let zh2 = ((await readConfig()).lang || "en") === "zh";
|
|
2668
2668
|
command && console.error(`${zh2 ? "\u672A\u77E5\u547D\u4EE4" : "Unknown command"}: "${command}"
|
|
2669
2669
|
`), printUsageHint(zh2);
|
|
@@ -2760,6 +2760,8 @@ async function runSync(flags) {
|
|
|
2760
2760
|
targetDates = [requestedDate];
|
|
2761
2761
|
else if (fromDate)
|
|
2762
2762
|
targetDates = buildDateRange(fromDate, toDate ?? getTodayDate());
|
|
2763
|
+
else if (flags.today === !0)
|
|
2764
|
+
targetDates = [getTodayDate()];
|
|
2763
2765
|
else {
|
|
2764
2766
|
let lookbackDays = typeof flags.lookback == "string" ? parsePositiveInt2(flags.lookback, "--lookback") : defaultLookbackDays(config);
|
|
2765
2767
|
targetDates = getClosedDates(lookbackDays), targetDates.push(getTodayDate());
|
|
@@ -2930,14 +2932,69 @@ async function runProjectAlias(args) {
|
|
|
2930
2932
|
if (!alias) throw new Error(zh2 ? "\u522B\u540D\u4E0D\u80FD\u4E3A\u7A7A" : "Alias cannot be empty");
|
|
2931
2933
|
config.projectAliases = { ...config.projectAliases ?? {}, [name]: alias }, await writeConfig(config), console.log(zh2 ? `\u5DF2\u8BBE\u7F6E: ${name} \u2192 ${alias}` : `Set: ${name} \u2192 ${alias}`);
|
|
2932
2934
|
}
|
|
2933
|
-
function printHelp() {
|
|
2934
|
-
let initialized = existsSync2(getConfigPath());
|
|
2935
|
+
function printHelp(zh2 = !1) {
|
|
2935
2936
|
console.log(`aiusage v${getVersion()}
|
|
2936
|
-
`)
|
|
2937
|
+
`);
|
|
2938
|
+
let cmds = zh2 ? [
|
|
2939
|
+
["scan [--date YYYY-MM-DD] [--json]", "\u626B\u63CF\u67D0\u65E5\u7528\u91CF\u660E\u7EC6"],
|
|
2940
|
+
["report [--range 7d|1m|3m|all] [--detail] [--json]", "\u672C\u5730\u7528\u91CF\u62A5\u544A"],
|
|
2941
|
+
["sync [--today] [--lookback N] [--date YYYY-MM-DD]", "\u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"],
|
|
2942
|
+
["sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "\u4E0A\u4F20\u6307\u5B9A\u65E5\u671F\u8303\u56F4"],
|
|
2943
|
+
["project [list]", "\u5217\u51FA\u672C\u673A\u6240\u6709\u9879\u76EE"],
|
|
2944
|
+
["project alias [<\u540D\u79F0> <\u522B\u540D>]", "\u67E5\u770B\u6216\u8BBE\u7F6E\u9879\u76EE\u522B\u540D"],
|
|
2945
|
+
["project alias --remove <\u540D\u79F0>", "\u79FB\u9664\u9879\u76EE\u522B\u540D"],
|
|
2946
|
+
["schedule [on|off|status] [--every 5m]", "\u5B9A\u65F6\u540C\u6B65\u7BA1\u7406"],
|
|
2947
|
+
["doctor", "\u8BCA\u65AD\u68C0\u67E5"],
|
|
2948
|
+
["config set <key> <value>", "\u4FEE\u6539\u914D\u7F6E"],
|
|
2949
|
+
["init [--device-id ID] [--device-name NAME]", "\u521D\u59CB\u5316\u672C\u5730\u914D\u7F6E"],
|
|
2950
|
+
["enroll --server URL --site-id ID --enroll-token TOKEN", "\u6CE8\u518C\u8BBE\u5907\u5230\u670D\u52A1\u7AEF"],
|
|
2951
|
+
["health [--server URL]", "\u6D4B\u8BD5\u670D\u52A1\u7AEF\u8FDE\u901A\u6027"]
|
|
2952
|
+
] : [
|
|
2953
|
+
["scan [--date YYYY-MM-DD] [--json]", "Scan daily usage breakdown"],
|
|
2954
|
+
["report [--range 7d|1m|3m|all] [--detail] [--json]", "Local usage report"],
|
|
2955
|
+
["sync [--today] [--lookback N] [--date YYYY-MM-DD]", "Upload usage to server"],
|
|
2956
|
+
["sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "Upload specific date range"],
|
|
2957
|
+
["project [list]", "List all projects"],
|
|
2958
|
+
["project alias [<name> <alias>]", "View or set project alias"],
|
|
2959
|
+
["project alias --remove <name>", "Remove project alias"],
|
|
2960
|
+
["schedule [on|off|status] [--every 5m]", "Scheduled sync management"],
|
|
2961
|
+
["doctor", "Run diagnostics"],
|
|
2962
|
+
["config set <key> <value>", "Update config"],
|
|
2963
|
+
["init [--device-id ID] [--device-name NAME]", "Initialize local config"],
|
|
2964
|
+
["enroll --server URL --site-id ID --enroll-token TOKEN", "Register device with server"],
|
|
2965
|
+
["health [--server URL]", "Test server connectivity"]
|
|
2966
|
+
], dw = (s) => [...s].reduce((w, c) => w + (c.charCodeAt(0) > 127 ? 2 : 1), 0), pad = (s, width) => s + " ".repeat(Math.max(0, width - dw(s))), maxCmd = Math.max(...cmds.map((c) => dw(c[0])));
|
|
2967
|
+
console.log(zh2 ? "\u547D\u4EE4:" : "Commands:");
|
|
2968
|
+
for (let [cmd, desc] of cmds)
|
|
2969
|
+
console.log(` ${pad(cmd, maxCmd + 2)} ${desc}`);
|
|
2970
|
+
console.log(""), console.log(`${zh2 ? "\u914D\u7F6E\u6587\u4EF6" : "Config"}: ${getConfigPath()}`);
|
|
2937
2971
|
}
|
|
2938
2972
|
function printUsageHint(zh2 = !1) {
|
|
2939
2973
|
console.log(`aiusage v${getVersion()}
|
|
2940
|
-
`)
|
|
2974
|
+
`);
|
|
2975
|
+
let cmds = zh2 ? [
|
|
2976
|
+
["scan [--date YYYY-MM-DD]", "\u626B\u63CF\u67D0\u65E5\u7528\u91CF\u660E\u7EC6"],
|
|
2977
|
+
["report [--range 7d|1m|3m|all]", "\u672C\u5730\u7528\u91CF\u62A5\u544A"],
|
|
2978
|
+
["sync [--today]", "\u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"],
|
|
2979
|
+
["project [list]", "\u5217\u51FA\u672C\u673A\u6240\u6709\u9879\u76EE"],
|
|
2980
|
+
["project alias [<\u540D\u79F0> <\u522B\u540D>]", "\u67E5\u770B\u6216\u8BBE\u7F6E\u9879\u76EE\u522B\u540D"],
|
|
2981
|
+
["schedule [on|off|status]", "\u5B9A\u65F6\u540C\u6B65\u7BA1\u7406"],
|
|
2982
|
+
["doctor", "\u8BCA\u65AD\u68C0\u67E5"],
|
|
2983
|
+
["config set <key> <value>", "\u4FEE\u6539\u914D\u7F6E"]
|
|
2984
|
+
] : [
|
|
2985
|
+
["scan [--date YYYY-MM-DD]", "Scan daily usage breakdown"],
|
|
2986
|
+
["report [--range 7d|1m|3m|all]", "Local usage report"],
|
|
2987
|
+
["sync [--today]", "Upload usage to server"],
|
|
2988
|
+
["project [list]", "List all projects"],
|
|
2989
|
+
["project alias [<name> <alias>]", "View or set project alias"],
|
|
2990
|
+
["schedule [on|off|status]", "Scheduled sync management"],
|
|
2991
|
+
["doctor", "Run diagnostics"],
|
|
2992
|
+
["config set <key> <value>", "Update config"]
|
|
2993
|
+
], dw2 = (s) => [...s].reduce((w, c) => w + (c.charCodeAt(0) > 127 ? 2 : 1), 0), pad2 = (s, width) => s + " ".repeat(Math.max(0, width - dw2(s))), maxCmd2 = Math.max(...cmds.map((c) => dw2(c[0])));
|
|
2994
|
+
console.log(zh2 ? "\u5E38\u7528\u547D\u4EE4:" : "Commands:");
|
|
2995
|
+
for (let [cmd, desc] of cmds)
|
|
2996
|
+
console.log(` ${pad2(cmd, maxCmd2 + 2)} ${desc}`);
|
|
2997
|
+
console.log(""), console.log(`${zh2 ? "\u914D\u7F6E\u6587\u4EF6" : "Config"}: ${getConfigPath()}`);
|
|
2941
2998
|
}
|
|
2942
2999
|
function parseArgs(args) {
|
|
2943
3000
|
let flags = {}, positionals = [];
|