@aiusage/cli 1.2.0 → 1.2.2
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 +27 -18
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2482,11 +2482,21 @@ try {
|
|
|
2482
2482
|
await runConfigSet(argv.slice(2));
|
|
2483
2483
|
else if (command === "project") {
|
|
2484
2484
|
let sub = argv[1];
|
|
2485
|
-
|
|
2486
|
-
|
|
2485
|
+
if (sub === "list") {
|
|
2486
|
+
let parsed = parseArgs(argv.slice(2));
|
|
2487
|
+
await runProjectList(parsed.flags);
|
|
2488
|
+
} else sub === void 0 ? await runProjectList() : sub === "alias" ? await runProjectAlias(argv.slice(2)) : (console.error(`\u672A\u77E5\u5B50\u547D\u4EE4: project ${sub}`), console.log("\u53EF\u7528: aiusage project list, aiusage project alias <\u9879\u76EE\u540D> <\u522B\u540D>"), process.exitCode = 1);
|
|
2489
|
+
} else if (command === "setup")
|
|
2490
|
+
console.log(`To deploy the server, clone the repo and run the setup wizard:
|
|
2487
2491
|
`), console.log(" git clone https://github.com/ennann/aiusage.git"), console.log(" cd aiusage && pnpm install"), console.log(` pnpm setup
|
|
2488
|
-
`), console.log("See: https://github.com/ennann/aiusage#deploy-your-own-server")
|
|
2489
|
-
|
|
2492
|
+
`), console.log("See: https://github.com/ennann/aiusage#deploy-your-own-server");
|
|
2493
|
+
else if (command === "--help" || command === "-h" || command === "help")
|
|
2494
|
+
printHelp();
|
|
2495
|
+
else {
|
|
2496
|
+
let zh2 = ((await readConfig()).lang || "en") === "zh";
|
|
2497
|
+
command && console.error(`${zh2 ? "\u672A\u77E5\u547D\u4EE4" : "Unknown command"}: "${command}"
|
|
2498
|
+
`), printUsageHint(zh2);
|
|
2499
|
+
}
|
|
2490
2500
|
} catch (error) {
|
|
2491
2501
|
console.error(error instanceof Error ? error.message : String(error)), process.exitCode = 1;
|
|
2492
2502
|
}
|
|
@@ -2664,22 +2674,21 @@ async function runConfigSet(args) {
|
|
|
2664
2674
|
let config = await readConfig(), next = setConfigValue(config, keyPath, values);
|
|
2665
2675
|
await writeConfig(next), console.log(JSON.stringify({ configPath: getConfigPath(), updated: keyPath }, null, 2));
|
|
2666
2676
|
}
|
|
2667
|
-
async function runProjectList() {
|
|
2668
|
-
let config = await readConfig(), projects = await discoverProjects(config.projectAliases);
|
|
2677
|
+
async function runProjectList(flags = {}) {
|
|
2678
|
+
let config = await readConfig(), zh2 = ((typeof flags.lang == "string" ? flags.lang : config.lang) || "en") === "zh", projects = await discoverProjects(config.projectAliases);
|
|
2669
2679
|
if (projects.length === 0) {
|
|
2670
|
-
console.log("\u672A\u53D1\u73B0\u4EFB\u4F55\u9879\u76EE\u3002");
|
|
2680
|
+
console.log(zh2 ? "\u672A\u53D1\u73B0\u4EFB\u4F55\u9879\u76EE\u3002" : "No projects found.");
|
|
2671
2681
|
return;
|
|
2672
2682
|
}
|
|
2673
|
-
let nameWidth = Math.max(
|
|
2674
|
-
console.log(
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
console.log(
|
|
2679
|
-
|
|
2680
|
-
);
|
|
2683
|
+
let 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))), hName = zh2 ? "\u9879\u76EE" : "Project", hAlias = zh2 ? "\u522B\u540D" : "Alias", hSource = zh2 ? "\u6765\u6E90" : "Source", nameWidth = Math.max(dw(hName), ...projects.map((p) => dw(p.name))), aliasWidth = Math.max(dw(hAlias), ...projects.map((p) => dw(p.alias ?? "-")));
|
|
2684
|
+
console.log(pad(hName, nameWidth + 2) + pad(hAlias, aliasWidth + 2) + hSource), console.log("-".repeat(nameWidth + aliasWidth + 20));
|
|
2685
|
+
let breakUrl = (s) => s.replace(/\./g, "\u200B.");
|
|
2686
|
+
for (let p of projects) {
|
|
2687
|
+
let line = pad(p.name, nameWidth + 2) + pad(p.alias ?? "-", aliasWidth + 2) + p.sources.join(", ");
|
|
2688
|
+
console.log(breakUrl(line));
|
|
2689
|
+
}
|
|
2681
2690
|
console.log(`
|
|
2682
|
-
\u5171 ${projects.length} \u4E2A\u9879\u76EE`);
|
|
2691
|
+
${zh2 ? "\u5171" : "Total:"} ${projects.length} ${zh2 ? "\u4E2A\u9879\u76EE" : "projects"}`);
|
|
2683
2692
|
}
|
|
2684
2693
|
async function runProjectAlias(args) {
|
|
2685
2694
|
if (args.length === 0) {
|
|
@@ -2713,9 +2722,9 @@ function printHelp() {
|
|
|
2713
2722
|
console.log(`aiusage v${getVersion()}
|
|
2714
2723
|
`), 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)"}`);
|
|
2715
2724
|
}
|
|
2716
|
-
function printUsageHint() {
|
|
2725
|
+
function printUsageHint(zh2 = !1) {
|
|
2717
2726
|
console.log(`aiusage v${getVersion()}
|
|
2718
|
-
`), 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()}`);
|
|
2727
|
+
`), 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()}`));
|
|
2719
2728
|
}
|
|
2720
2729
|
function parseArgs(args) {
|
|
2721
2730
|
let flags = {}, positionals = [];
|