fix(cli): 收敛逐级披露与输入错误
This commit is contained in:
+23
-4
@@ -1,6 +1,6 @@
|
||||
import { readConfig } from "./src/config";
|
||||
import { isHelpToken, sshHelp, sshHelpScope } from "./src/help";
|
||||
import { emitError, emitJson } from "./src/output";
|
||||
import { isHelpToken, renderSshHelpText, sshHelpScope } from "./src/help";
|
||||
import { CliInputError, emitError, emitText } from "./src/output";
|
||||
import { extractRemoteCliOptions } from "./src/remote-options";
|
||||
import { runRemoteSshCli } from "./src/remote-ssh";
|
||||
import { runSsh } from "./src/ssh";
|
||||
@@ -29,8 +29,27 @@ async function main(): Promise<void> {
|
||||
const [top, sub, third] = args;
|
||||
if (top !== "ssh") throw new Error(`ssh-cli supports only the ssh command, got: ${top || "<empty>"}`);
|
||||
|
||||
if (sub === undefined || isHelpToken(sub) || (isHelpToken(third) && args.length === 3)) {
|
||||
emitJson(commandName, sshHelp(sshHelpScope(args)));
|
||||
if (sub === undefined) {
|
||||
emitText(renderSshHelpText(), commandName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isHelpToken(sub)) {
|
||||
const scope = sshHelpScope(args);
|
||||
if (args.length > 2 && scope === undefined) {
|
||||
throw new CliInputError(`Unknown trans help scope: ${third ?? "<missing>"}`, {
|
||||
code: "unknown-help-scope",
|
||||
argument: third ?? "",
|
||||
usage: ["trans --help", "trans --help <operation>"],
|
||||
hint: "Use trans --help to list the bounded operation groups before opening scoped help.",
|
||||
});
|
||||
}
|
||||
emitText(renderSshHelpText(scope), commandName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isHelpToken(third) && args.length === 3) {
|
||||
emitText(renderSshHelpText(), commandName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user