CLI: drop web:login alias and simplify web quickstart
This commit is contained in:
@@ -24,23 +24,9 @@ export function buildProgram() {
|
||||
.description("WhatsApp relay CLI (Twilio or WhatsApp Web session)")
|
||||
.version("1.0.0");
|
||||
|
||||
program
|
||||
.command("web:login")
|
||||
.description("Link your personal WhatsApp via QR (web provider)")
|
||||
.option("--verbose", "Verbose connection logs", false)
|
||||
.action(async (opts) => {
|
||||
setVerbose(Boolean(opts.verbose));
|
||||
try {
|
||||
await loginWeb(Boolean(opts.verbose));
|
||||
} catch (err) {
|
||||
defaultRuntime.error(danger(`Web login failed: ${String(err)}`));
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
program
|
||||
.command("login")
|
||||
.description("Alias for web:login (personal WhatsApp Web QR link)")
|
||||
.description("Link your personal WhatsApp via QR (web provider)")
|
||||
.option("--verbose", "Verbose connection logs", false)
|
||||
.action(async (opts) => {
|
||||
setVerbose(Boolean(opts.verbose));
|
||||
|
||||
@@ -26,10 +26,9 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("CLI commands", () => {
|
||||
it("exposes login alias", () => {
|
||||
it("exposes login command", () => {
|
||||
const names = index.program.commands.map((c) => c.name());
|
||||
expect(names).toContain("login");
|
||||
expect(names).toContain("web:login");
|
||||
});
|
||||
|
||||
it("send command routes to web provider", async () => {
|
||||
@@ -87,7 +86,7 @@ describe("CLI commands", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("login alias calls web login", async () => {
|
||||
it("login command calls web login", async () => {
|
||||
const spy = vi.spyOn(providerWeb, "loginWeb").mockResolvedValue();
|
||||
await index.program.parseAsync(["login"], { from: "user" });
|
||||
expect(spy).toHaveBeenCalled();
|
||||
|
||||
@@ -65,9 +65,7 @@ export async function createWaSocket(printQr: boolean, verbose: boolean) {
|
||||
if (connection === "close") {
|
||||
const status = getStatusCode(lastDisconnect?.error);
|
||||
if (status === DisconnectReason.loggedOut) {
|
||||
console.error(
|
||||
danger("WhatsApp session logged out. Run: warelay web:login"),
|
||||
);
|
||||
console.error(danger("WhatsApp session logged out. Run: warelay login"));
|
||||
}
|
||||
}
|
||||
if (connection === "open" && verbose) {
|
||||
@@ -191,10 +189,10 @@ export async function loginWeb(
|
||||
await fs.rm(WA_WEB_AUTH_DIR, { recursive: true, force: true });
|
||||
console.error(
|
||||
danger(
|
||||
"WhatsApp reported the session is logged out. Cleared cached web session; please rerun warelay web:login and scan the QR again.",
|
||||
"WhatsApp reported the session is logged out. Cleared cached web session; please rerun warelay login and scan the QR again.",
|
||||
),
|
||||
);
|
||||
throw new Error("Session logged out; cache cleared. Re-run web:login.");
|
||||
throw new Error("Session logged out; cache cleared. Re-run login.");
|
||||
}
|
||||
const formatted = formatError(err);
|
||||
console.error(
|
||||
|
||||
Reference in New Issue
Block a user