@aiusage/cli 1.2.2 → 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 +21 -14
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2485,7 +2485,14 @@ 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
|
|
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
|
+
}
|
|
2489
2496
|
} else if (command === "setup")
|
|
2490
2497
|
console.log(`To deploy the server, clone the repo and run the setup wizard:
|
|
2491
2498
|
`), console.log(" git clone https://github.com/ennann/aiusage.git"), console.log(" cd aiusage && pnpm install"), console.log(` pnpm setup
|
|
@@ -2501,8 +2508,8 @@ try {
|
|
|
2501
2508
|
console.error(error instanceof Error ? error.message : String(error)), process.exitCode = 1;
|
|
2502
2509
|
}
|
|
2503
2510
|
async function runScan(date, isJson) {
|
|
2504
|
-
let config = await readConfig();
|
|
2505
|
-
isJson || console.log(
|
|
2511
|
+
let config = await readConfig(), zh2 = config.lang === "zh";
|
|
2512
|
+
isJson || console.log(`${zh2 ? "\u626B\u63CF\u65E5\u671F" : "Scan date"}: ${date}
|
|
2506
2513
|
`);
|
|
2507
2514
|
let result = await scanDate(date, { projectAliases: config.projectAliases });
|
|
2508
2515
|
if (isJson) {
|
|
@@ -2510,7 +2517,7 @@ async function runScan(date, isJson) {
|
|
|
2510
2517
|
return;
|
|
2511
2518
|
}
|
|
2512
2519
|
if (result.breakdowns.length === 0) {
|
|
2513
|
-
console.log("\u8BE5\u65E5\u65E0\u6570\u636E\u3002");
|
|
2520
|
+
console.log(zh2 ? "\u8BE5\u65E5\u65E0\u6570\u636E\u3002" : "No data for this date.");
|
|
2514
2521
|
return;
|
|
2515
2522
|
}
|
|
2516
2523
|
let byProvider = /* @__PURE__ */ new Map();
|
|
@@ -2691,10 +2698,11 @@ async function runProjectList(flags = {}) {
|
|
|
2691
2698
|
${zh2 ? "\u5171" : "Total:"} ${projects.length} ${zh2 ? "\u4E2A\u9879\u76EE" : "projects"}`);
|
|
2692
2699
|
}
|
|
2693
2700
|
async function runProjectAlias(args) {
|
|
2701
|
+
let config = await readConfig(), zh2 = config.lang === "zh";
|
|
2694
2702
|
if (args.length === 0) {
|
|
2695
|
-
let aliases =
|
|
2703
|
+
let aliases = config.projectAliases ?? {}, entries = Object.entries(aliases);
|
|
2696
2704
|
if (entries.length === 0) {
|
|
2697
|
-
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>");
|
|
2698
2706
|
return;
|
|
2699
2707
|
}
|
|
2700
2708
|
for (let [from, to] of entries)
|
|
@@ -2703,19 +2711,18 @@ async function runProjectAlias(args) {
|
|
|
2703
2711
|
}
|
|
2704
2712
|
if (args[0] === "--remove") {
|
|
2705
2713
|
let name2 = args.slice(1).join(" ").trim();
|
|
2706
|
-
if (!name2) throw new Error("\u8BF7\u6307\u5B9A\u8981\u79FB\u9664\u522B\u540D\u7684\u9879\u76EE\u540D");
|
|
2707
|
-
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 ?? {} };
|
|
2708
2716
|
if (!(name2 in aliases))
|
|
2709
|
-
throw new Error(`\u9879\u76EE "${name2}" \u672A\u8BBE\u7F6E\u522B\u540D`);
|
|
2710
|
-
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}".`);
|
|
2711
2719
|
return;
|
|
2712
2720
|
}
|
|
2713
2721
|
if (args.length < 2)
|
|
2714
|
-
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>");
|
|
2715
2723
|
let name = args[0], alias = args.slice(1).join(" ").trim();
|
|
2716
|
-
if (!alias) throw new Error("\u522B\u540D\u4E0D\u80FD\u4E3A\u7A7A");
|
|
2717
|
-
|
|
2718
|
-
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}`);
|
|
2719
2726
|
}
|
|
2720
2727
|
function printHelp() {
|
|
2721
2728
|
let initialized = existsSync2(getConfigPath());
|