@minato-aqukin/autodl-cli 0.1.0

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.
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __nodeCreateRequire } from "node:module";
3
+ const require = __nodeCreateRequire(import.meta.url);
4
+ import {
5
+ createContext,
6
+ runOpportunisticSweep
7
+ } from "./chunk-NBWWTYSL.js";
8
+ import {
9
+ ExitCode,
10
+ UsageError,
11
+ configureOutput,
12
+ emitError,
13
+ isJson,
14
+ resolveLang,
15
+ setLang,
16
+ toAutoDLError
17
+ } from "./chunk-6QR4ZYQR.js";
18
+
19
+ // src/commands/helpers.ts
20
+ import { confirm, isCancel } from "@clack/prompts";
21
+ function globalsOf(command) {
22
+ let root = command;
23
+ while (root.parent) root = root.parent;
24
+ return root.opts();
25
+ }
26
+ function action(handler, { sweep = true } = {}) {
27
+ return async (...args) => {
28
+ const command = args[args.length - 1];
29
+ const globals = globalsOf(command);
30
+ try {
31
+ const context = createContext(globals);
32
+ if (sweep) await runOpportunisticSweep(context, globals);
33
+ const code = await handler(context, ...args);
34
+ process.exitCode = typeof code === "number" ? code : ExitCode.OK;
35
+ } catch (err) {
36
+ const error = toAutoDLError(err);
37
+ emitError(error);
38
+ process.exitCode = error.exitCode;
39
+ }
40
+ };
41
+ }
42
+ function lazyAction(handler) {
43
+ return async (...args) => {
44
+ const command = args[args.length - 1];
45
+ const globals = globalsOf(command);
46
+ try {
47
+ let context;
48
+ const getContext = () => {
49
+ if (!context) context = createContext(globals);
50
+ return context;
51
+ };
52
+ configureOutput({
53
+ json: globals.json ?? false,
54
+ color: globals.color ?? true,
55
+ verbose: globals.verbose ?? false
56
+ });
57
+ setLang(resolveLang(globals.lang));
58
+ const code = await handler(getContext, ...args);
59
+ if (context) await runOpportunisticSweep(context, globals);
60
+ process.exitCode = typeof code === "number" ? code : ExitCode.OK;
61
+ } catch (err) {
62
+ const error = toAutoDLError(err);
63
+ emitError(error);
64
+ process.exitCode = error.exitCode;
65
+ }
66
+ };
67
+ }
68
+ function bareAction(handler) {
69
+ return async (...args) => {
70
+ const command = args[args.length - 1];
71
+ const globals = globalsOf(command);
72
+ try {
73
+ const code = await handler(globals, ...args);
74
+ process.exitCode = typeof code === "number" ? code : ExitCode.OK;
75
+ } catch (err) {
76
+ const error = toAutoDLError(err);
77
+ emitError(error);
78
+ process.exitCode = error.exitCode;
79
+ }
80
+ };
81
+ }
82
+ async function confirmDestructive(message, yes) {
83
+ if (yes) return true;
84
+ if (isJson() || !process.stdin.isTTY) {
85
+ throw new UsageError(`${message}\uFF1A\u9700\u8981\u663E\u5F0F\u786E\u8BA4`, {
86
+ hint: "\u975E\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u8BF7\u52A0 --yes \u660E\u786E\u786E\u8BA4\u8FD9\u9879\u4E0D\u53EF\u9006\u64CD\u4F5C\u3002"
87
+ });
88
+ }
89
+ const answer = await confirm({ message });
90
+ if (isCancel(answer)) return false;
91
+ return answer === true;
92
+ }
93
+
94
+ // src/commands/tui.ts
95
+ function assertInteractive(json) {
96
+ if (json) {
97
+ throw new UsageError("TUI \u662F\u4EA4\u4E92\u5F0F\u754C\u9762\uFF0C\u4E0D\u80FD\u4E0E --json \u4E00\u8D77\u4F7F\u7528", {
98
+ hint: "\u9700\u8981\u673A\u5668\u53EF\u8BFB\u8F93\u51FA\u8BF7\u7528 `autodl ls --json` \u7B49\u547D\u4EE4\u3002"
99
+ });
100
+ }
101
+ if (!process.stdout.isTTY || !process.stdin.isTTY) {
102
+ throw new UsageError("\u5F53\u524D\u4E0D\u662F\u4EA4\u4E92\u5F0F\u7EC8\u7AEF\uFF0C\u65E0\u6CD5\u542F\u52A8 TUI", {
103
+ hint: "TUI \u9700\u8981\u771F\u5B9E\u7EC8\u7AEF\u3002\u5728\u7BA1\u9053\u3001CI \u6216 agent \u8C03\u7528\u4E2D\u8BF7\u4F7F\u7528\u666E\u901A\u5B50\u547D\u4EE4\u3002"
104
+ });
105
+ }
106
+ }
107
+ async function launchTui(globals) {
108
+ assertInteractive(globals.json === true);
109
+ const { runTui } = await import("./app-4E2WPQ3C.js");
110
+ await runTui({
111
+ ...globals.token ? { token: globals.token } : {},
112
+ ...globals.baseUrl ? { baseUrl: globals.baseUrl } : {}
113
+ });
114
+ }
115
+ function registerTuiCommand(program) {
116
+ program.command("tui").description("\u542F\u52A8\u4EA4\u4E92\u5F0F\u770B\u677F\uFF08\u5B9E\u4F8B\u3001\u8D39\u7528\u3001\u5E93\u5B58\u3001\u521B\u5EFA\uFF09").action(
117
+ bareAction(async (_globals, _options, command) => {
118
+ await launchTui(globalsOf(command));
119
+ return 0;
120
+ })
121
+ );
122
+ }
123
+
124
+ export {
125
+ globalsOf,
126
+ action,
127
+ lazyAction,
128
+ bareAction,
129
+ confirmDestructive,
130
+ assertInteractive,
131
+ launchTui,
132
+ registerTuiCommand
133
+ };
134
+ //# sourceMappingURL=chunk-2TWWLI3Y.js.map