tt-help-cli-ycl 1.3.35 → 1.3.37

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/src/main.js CHANGED
@@ -1,28 +1,50 @@
1
- import { parseArgs } from './lib/args.js';
2
- import { proxy, HELP_TEXT, getConfigText } from './lib/constants.js';
3
- import { handleInfo } from './cli/info.js';
4
- import { handleExplore } from './cli/explore.js';
5
- import { handleAttach } from './cli/attach.js';
6
- import { handleWatch } from './cli/watch.js';
7
- import { handleConfig, showConfig, showUsage, version } from './cli/config.js';
8
- import { handleOpen } from './cli/open.js';
9
- import { handleComments } from './cli/comments.js';
10
- import { handleVideoStats } from './cli/videostats.js';
1
+ import { parseArgs } from "./lib/args.js";
2
+ import { proxy, HELP_TEXT, getConfigText } from "./lib/constants.js";
3
+ import { handleInfo } from "./cli/info.js";
4
+ import { handleExplore } from "./cli/explore.js";
5
+ import { handleAttach } from "./cli/attach.js";
6
+ import { handleWatch } from "./cli/watch.js";
7
+ import { handleConfig, showConfig, showUsage, version } from "./cli/config.js";
8
+ import { handleOpen } from "./cli/open.js";
9
+ import { handleComments } from "./cli/comments.js";
10
+ import { handleVideoStats } from "./cli/videostats.js";
11
+ import { handleDbImport } from "./cli/db-import.js";
11
12
 
12
13
  async function main() {
13
14
  const parsed = parseArgs();
14
15
 
15
16
  switch (parsed.subcommand) {
16
- case 'explore': return handleExplore(parsed);
17
- case 'info': return handleInfo(parsed);
18
- case 'attach': return handleAttach(parsed);
19
- case 'watch': return handleWatch(parsed);
20
- case 'open': return handleOpen(parsed);
21
- case 'comments': return handleComments(parsed);
22
- case 'videostats': return handleVideoStats(parsed);
17
+ case "explore":
18
+ return handleExplore(parsed);
19
+ case "info":
20
+ return handleInfo(parsed);
21
+ case "attach":
22
+ return handleAttach(parsed);
23
+ case "watch":
24
+ return handleWatch(parsed);
25
+ case "open":
26
+ return handleOpen(parsed);
27
+ case "comments":
28
+ return handleComments(parsed);
29
+ case "videostats":
30
+ return handleVideoStats(parsed);
31
+ case "db-import":
32
+ return handleDbImport(parsed);
23
33
  }
24
34
 
25
- const { urls, outputFile, outputFormat, exploreCount, showConfig: showCfg, showHelp, showVersion, customProxy, configAction, configKey, configValue } = parsed;
35
+ const {
36
+ urls,
37
+ outputFile,
38
+ outputFormat,
39
+ exploreCount,
40
+ showConfig: showCfg,
41
+ showHelp,
42
+ showVersion,
43
+ customProxy,
44
+ configAction,
45
+ configKey,
46
+ configValue,
47
+ } = parsed;
26
48
 
27
49
  if (showVersion) {
28
50
  console.log(version);
@@ -35,14 +57,14 @@ async function main() {
35
57
 
36
58
  // 默认行为:URL 走 info,--explore 走 explore
37
59
  if (exploreCount > 0) {
38
- return handleExplore({ ...parsed, subcommand: 'explore' });
60
+ return handleExplore({ ...parsed, subcommand: "explore" });
39
61
  }
40
62
 
41
63
  // 有 URL 默认走 info
42
64
  return handleInfo(parsed);
43
65
  }
44
66
 
45
- main().catch(err => {
67
+ main().catch((err) => {
46
68
  console.error(`错误: ${err.message}`);
47
69
  process.exit(1);
48
70
  });
@@ -0,0 +1,69 @@
1
+ import { parseArgs } from "./lib/args.js";
2
+ import { PUBLIC_HELP_TEXT } from "./lib/constants.js";
3
+ import { handleInfo } from "./cli/info.js";
4
+ import { handleExplore } from "./cli/explore.js";
5
+ import { handleAttach } from "./cli/attach.js";
6
+ import { handleConfig, showConfig, showUsage, version } from "./cli/config.js";
7
+ import { handleOpen } from "./cli/open.js";
8
+ import { handleComments } from "./cli/comments.js";
9
+
10
+ function exitUnsupportedCommand(command) {
11
+ console.error(
12
+ `[${command}] 当前 npm 发布包不包含该命令;如需使用,请在仓库源码环境中运行 node src/main.js ${command} ...`,
13
+ );
14
+ process.exit(1);
15
+ }
16
+
17
+ async function main() {
18
+ const parsed = parseArgs();
19
+
20
+ switch (parsed.subcommand) {
21
+ case "explore":
22
+ return handleExplore(parsed);
23
+ case "info":
24
+ return handleInfo(parsed);
25
+ case "attach":
26
+ return handleAttach(parsed);
27
+ case "watch":
28
+ case "videostats":
29
+ case "db-import":
30
+ return exitUnsupportedCommand(parsed.subcommand);
31
+ case "open":
32
+ return handleOpen(parsed);
33
+ case "comments":
34
+ return handleComments(parsed);
35
+ }
36
+
37
+ const {
38
+ urls,
39
+ outputFile,
40
+ exploreCount,
41
+ showConfig: showCfg,
42
+ showHelp,
43
+ showVersion,
44
+ configAction,
45
+ configKey,
46
+ configValue,
47
+ } = parsed;
48
+
49
+ if (showVersion) {
50
+ console.log(version);
51
+ process.exit(0);
52
+ }
53
+ if (showHelp) return showUsage(PUBLIC_HELP_TEXT);
54
+ if (configAction) return handleConfig(configAction, configKey, configValue);
55
+ if (showCfg) return showConfig(urls, outputFile);
56
+ if (urls.length === 0 && exploreCount === 0)
57
+ return showUsage(PUBLIC_HELP_TEXT);
58
+
59
+ if (exploreCount > 0) {
60
+ return handleExplore({ ...parsed, subcommand: "explore" });
61
+ }
62
+
63
+ return handleInfo(parsed);
64
+ }
65
+
66
+ main().catch((err) => {
67
+ console.error(`错误: ${err.message}`);
68
+ process.exit(1);
69
+ });