@aiusage/cli 1.2.1 → 1.2.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 +33 -19
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2485,17 +2485,31 @@ try {
|
|
|
2485
2485
|
if (sub === "list") {
|
|
2486
2486
|
let parsed = parseArgs(argv.slice(2));
|
|
2487
2487
|
await runProjectList(parsed.flags);
|
|
2488
|
-
} else sub === void 0
|
|
2489
|
-
|
|
2488
|
+
} else if (sub === void 0)
|
|
2489
|
+
await runProjectList();
|
|
2490
|
+
else if (sub === "alias")
|
|
2491
|
+
await runProjectAlias(argv.slice(2));
|
|
2492
|
+
else {
|
|
2493
|
+
let zh2 = (await readConfig()).lang === "zh";
|
|
2494
|
+
console.error(`${zh2 ? "\u672A\u77E5\u5B50\u547D\u4EE4" : "Unknown subcommand"}: project ${sub}`), console.log(zh2 ? "\u53EF\u7528: aiusage project list, aiusage project alias <\u9879\u76EE\u540D> <\u522B\u540D>" : "Available: aiusage project list, aiusage project alias <name> <alias>"), process.exitCode = 1;
|
|
2495
|
+
}
|
|
2496
|
+
} else if (command === "setup")
|
|
2497
|
+
console.log(`To deploy the server, clone the repo and run the setup wizard:
|
|
2490
2498
|
`), console.log(" git clone https://github.com/ennann/aiusage.git"), console.log(" cd aiusage && pnpm install"), console.log(` pnpm setup
|
|
2491
|
-
`), console.log("See: https://github.com/ennann/aiusage#deploy-your-own-server")
|
|
2492
|
-
|
|
2499
|
+
`), console.log("See: https://github.com/ennann/aiusage#deploy-your-own-server");
|
|
2500
|
+
else if (command === "--help" || command === "-h" || command === "help")
|
|
2501
|
+
printHelp();
|
|
2502
|
+
else {
|
|
2503
|
+
let zh2 = ((await readConfig()).lang || "en") === "zh";
|
|
2504
|
+
command && console.error(`${zh2 ? "\u672A\u77E5\u547D\u4EE4" : "Unknown command"}: "${command}"
|
|
2505
|
+
`), printUsageHint(zh2);
|
|
2506
|
+
}
|
|
2493
2507
|
} catch (error) {
|
|
2494
2508
|
console.error(error instanceof Error ? error.message : String(error)), process.exitCode = 1;
|
|
2495
2509
|
}
|
|
2496
2510
|
async function runScan(date, isJson) {
|
|
2497
|
-
let config = await readConfig();
|
|
2498
|
-
isJson || console.log(
|
|
2511
|
+
let config = await readConfig(), zh2 = config.lang === "zh";
|
|
2512
|
+
isJson || console.log(`${zh2 ? "\u626B\u63CF\u65E5\u671F" : "Scan date"}: ${date}
|
|
2499
2513
|
`);
|
|
2500
2514
|
let result = await scanDate(date, { projectAliases: config.projectAliases });
|
|
2501
2515
|
if (isJson) {
|
|
@@ -2503,7 +2517,7 @@ async function runScan(date, isJson) {
|
|
|
2503
2517
|
return;
|
|
2504
2518
|
}
|
|
2505
2519
|
if (result.breakdowns.length === 0) {
|
|
2506
|
-
console.log("\u8BE5\u65E5\u65E0\u6570\u636E\u3002");
|
|
2520
|
+
console.log(zh2 ? "\u8BE5\u65E5\u65E0\u6570\u636E\u3002" : "No data for this date.");
|
|
2507
2521
|
return;
|
|
2508
2522
|
}
|
|
2509
2523
|
let byProvider = /* @__PURE__ */ new Map();
|
|
@@ -2684,10 +2698,11 @@ async function runProjectList(flags = {}) {
|
|
|
2684
2698
|
${zh2 ? "\u5171" : "Total:"} ${projects.length} ${zh2 ? "\u4E2A\u9879\u76EE" : "projects"}`);
|
|
2685
2699
|
}
|
|
2686
2700
|
async function runProjectAlias(args) {
|
|
2701
|
+
let config = await readConfig(), zh2 = config.lang === "zh";
|
|
2687
2702
|
if (args.length === 0) {
|
|
2688
|
-
let aliases =
|
|
2703
|
+
let aliases = config.projectAliases ?? {}, entries = Object.entries(aliases);
|
|
2689
2704
|
if (entries.length === 0) {
|
|
2690
|
-
console.log("\u5C1A\u672A\u8BBE\u7F6E\u4EFB\u4F55\u9879\u76EE\u522B\u540D\u3002"), console.log("\u7528\u6CD5: aiusage project alias <\u9879\u76EE\u540D> <\u522B\u540D>");
|
|
2705
|
+
console.log(zh2 ? "\u5C1A\u672A\u8BBE\u7F6E\u4EFB\u4F55\u9879\u76EE\u522B\u540D\u3002" : "No project aliases configured."), console.log(zh2 ? "\u7528\u6CD5: aiusage project alias <\u9879\u76EE\u540D> <\u522B\u540D>" : "Usage: aiusage project alias <name> <alias>");
|
|
2691
2706
|
return;
|
|
2692
2707
|
}
|
|
2693
2708
|
for (let [from, to] of entries)
|
|
@@ -2696,28 +2711,27 @@ async function runProjectAlias(args) {
|
|
|
2696
2711
|
}
|
|
2697
2712
|
if (args[0] === "--remove") {
|
|
2698
2713
|
let name2 = args.slice(1).join(" ").trim();
|
|
2699
|
-
if (!name2) throw new Error("\u8BF7\u6307\u5B9A\u8981\u79FB\u9664\u522B\u540D\u7684\u9879\u76EE\u540D");
|
|
2700
|
-
let
|
|
2714
|
+
if (!name2) throw new Error(zh2 ? "\u8BF7\u6307\u5B9A\u8981\u79FB\u9664\u522B\u540D\u7684\u9879\u76EE\u540D" : "Please specify the project name to remove");
|
|
2715
|
+
let aliases = { ...config.projectAliases ?? {} };
|
|
2701
2716
|
if (!(name2 in aliases))
|
|
2702
|
-
throw new Error(`\u9879\u76EE "${name2}" \u672A\u8BBE\u7F6E\u522B\u540D`);
|
|
2703
|
-
delete aliases[name2],
|
|
2717
|
+
throw new Error(zh2 ? `\u9879\u76EE "${name2}" \u672A\u8BBE\u7F6E\u522B\u540D` : `No alias set for "${name2}"`);
|
|
2718
|
+
delete aliases[name2], config.projectAliases = Object.keys(aliases).length > 0 ? aliases : void 0, await writeConfig(config), console.log(zh2 ? `\u5DF2\u79FB\u9664 "${name2}" \u7684\u522B\u540D\u3002` : `Removed alias for "${name2}".`);
|
|
2704
2719
|
return;
|
|
2705
2720
|
}
|
|
2706
2721
|
if (args.length < 2)
|
|
2707
|
-
throw new Error("\u7528\u6CD5: aiusage project alias <\u9879\u76EE\u540D> <\u522B\u540D>");
|
|
2722
|
+
throw new Error(zh2 ? "\u7528\u6CD5: aiusage project alias <\u9879\u76EE\u540D> <\u522B\u540D>" : "Usage: aiusage project alias <name> <alias>");
|
|
2708
2723
|
let name = args[0], alias = args.slice(1).join(" ").trim();
|
|
2709
|
-
if (!alias) throw new Error("\u522B\u540D\u4E0D\u80FD\u4E3A\u7A7A");
|
|
2710
|
-
|
|
2711
|
-
config.projectAliases = { ...config.projectAliases ?? {}, [name]: alias }, await writeConfig(config), console.log(`\u5DF2\u8BBE\u7F6E: ${name} \u2192 ${alias}`);
|
|
2724
|
+
if (!alias) throw new Error(zh2 ? "\u522B\u540D\u4E0D\u80FD\u4E3A\u7A7A" : "Alias cannot be empty");
|
|
2725
|
+
config.projectAliases = { ...config.projectAliases ?? {}, [name]: alias }, await writeConfig(config), console.log(zh2 ? `\u5DF2\u8BBE\u7F6E: ${name} \u2192 ${alias}` : `Set: ${name} \u2192 ${alias}`);
|
|
2712
2726
|
}
|
|
2713
2727
|
function printHelp() {
|
|
2714
2728
|
let initialized = existsSync2(getConfigPath());
|
|
2715
2729
|
console.log(`aiusage v${getVersion()}
|
|
2716
2730
|
`), console.log("Usage: aiusage <command>"), console.log(""), console.log("Commands:"), console.log(" aiusage init [--device-id ID] [--device-name NAME] [--lookback N]"), console.log(" aiusage enroll --server URL --site-id ID --enroll-token TOKEN [--target NAME]"), console.log(" aiusage sync [--target NAME] [--date YYYY-MM-DD] [--from YYYY-MM-DD [--to YYYY-MM-DD]] [--lookback N] [--today]"), console.log(" aiusage health [--target NAME] [--server URL]"), console.log(" aiusage scan [--date YYYY-MM-DD] [--json]"), console.log(" aiusage report [--range 7d|1m|3m|all] [--detail] [--lang en|zh] [--no-emoji] [--json]"), console.log(" aiusage schedule [on|off|status] [--every 5m]"), console.log(" aiusage doctor"), console.log(" aiusage project [list]"), console.log(" aiusage project alias [<\u9879\u76EE\u540D> <\u522B\u540D>] [--remove <\u9879\u76EE\u540D>]"), console.log(" aiusage config set <key> <value...>"), console.log(""), console.log(`\u914D\u7F6E\u6587\u4EF6: ${getConfigPath()}${initialized ? "" : " (\u5C1A\u672A\u521D\u59CB\u5316)"}`);
|
|
2717
2731
|
}
|
|
2718
|
-
function printUsageHint() {
|
|
2732
|
+
function printUsageHint(zh2 = !1) {
|
|
2719
2733
|
console.log(`aiusage v${getVersion()}
|
|
2720
|
-
`), console.log("\u5E38\u7528\u547D\u4EE4:"), console.log(" scan [--date YYYY-MM-DD] \u626B\u63CF\u67D0\u65E5\u7528\u91CF\u660E\u7EC6"), console.log(" report [--range 7d|1m|3m|all] \u672C\u5730\u7528\u91CF\u62A5\u544A"), console.log(" project [list] \u5217\u51FA\u672C\u673A\u6240\u6709\u9879\u76EE"), console.log(" project alias <\u540D\u79F0> <\u522B\u540D> \u8BBE\u7F6E\u9879\u76EE\u522B\u540D"), console.log(" sync \u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"), console.log(" schedule [on|off|status] \u5B9A\u65F6\u540C\u6B65"), console.log(" doctor \u8BCA\u65AD\u68C0\u67E5"), console.log(" config set <key> <value> \u4FEE\u6539\u914D\u7F6E"), console.log(""), console.log(`\u914D\u7F6E\u6587\u4EF6: ${getConfigPath()}`);
|
|
2734
|
+
`), zh2 ? (console.log("\u5E38\u7528\u547D\u4EE4:"), console.log(" scan [--date YYYY-MM-DD] \u626B\u63CF\u67D0\u65E5\u7528\u91CF\u660E\u7EC6"), console.log(" report [--range 7d|1m|3m|all] \u672C\u5730\u7528\u91CF\u62A5\u544A"), console.log(" project [list] \u5217\u51FA\u672C\u673A\u6240\u6709\u9879\u76EE"), console.log(" project alias <\u540D\u79F0> <\u522B\u540D> \u8BBE\u7F6E\u9879\u76EE\u522B\u540D"), console.log(" sync \u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"), console.log(" schedule [on|off|status] \u5B9A\u65F6\u540C\u6B65"), console.log(" doctor \u8BCA\u65AD\u68C0\u67E5"), console.log(" config set <key> <value> \u4FEE\u6539\u914D\u7F6E"), console.log(""), console.log(`\u914D\u7F6E\u6587\u4EF6: ${getConfigPath()}`)) : (console.log("Commands:"), console.log(" scan [--date YYYY-MM-DD] Scan daily usage breakdown"), console.log(" report [--range 7d|1m|3m|all] Local usage report"), console.log(" project [list] List all projects"), console.log(" project alias <name> <alias> Set project alias"), console.log(" sync Upload usage to server"), console.log(" schedule [on|off|status] Scheduled sync"), console.log(" doctor Diagnostics"), console.log(" config set <key> <value> Update config"), console.log(""), console.log(`Config: ${getConfigPath()}`));
|
|
2721
2735
|
}
|
|
2722
2736
|
function parseArgs(args) {
|
|
2723
2737
|
let flags = {}, positionals = [];
|