diff --git a/src/cli.ts b/src/cli.ts index 711ee81..922840b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -9,6 +9,7 @@ import { broadcastsCommand } from './commands/broadcasts/index'; import { completionCommand } from './commands/completion'; import { contactPropertiesCommand } from './commands/contact-properties/index'; import { contactsCommand } from './commands/contacts/index'; +import { docsCommand } from './commands/docs'; import { doctorCommand } from './commands/doctor'; import { domainsCommand } from './commands/domains/index'; import { emailsCommand } from './commands/emails/index'; @@ -141,6 +142,7 @@ ${pc.gray('Examples:')} .addCommand(whoamiCommand) .addCommand(doctorCommand) .addCommand(openCommand) + .addCommand(docsCommand) .addCommand(updateCommand) .addCommand(teamsDeprecatedCommand) .addCommand(completionCommand); diff --git a/src/commands/docs.ts b/src/commands/docs.ts new file mode 100644 index 0000000..b481053 --- /dev/null +++ b/src/commands/docs.ts @@ -0,0 +1,19 @@ +import { Command } from '@commander-js/extra-typings'; +import { openInBrowserOrLog, RESEND_URLS } from '../lib/browser'; +import type { GlobalOpts } from '../lib/client'; +import { buildHelpText } from '../lib/help-text'; + +export const docsCommand = new Command('docs') + .description('Open the Resend documentation in your browser') + .addHelpText( + 'after', + buildHelpText({ + context: 'Opens https://resend.com/docs in your default browser.', + examples: ['resend docs'], + }), + ) + .action(async (_opts, cmd) => { + const globalOpts = cmd.optsWithGlobals() as GlobalOpts; + + await openInBrowserOrLog(RESEND_URLS.documentation, globalOpts); + }); diff --git a/src/lib/browser.ts b/src/lib/browser.ts index 2b6c969..7ad092e 100644 --- a/src/lib/browser.ts +++ b/src/lib/browser.ts @@ -65,4 +65,5 @@ export const RESEND_URLS = { template: (id: string) => `${RESEND_BASE}/templates/${id}`, broadcasts: `${RESEND_BASE}/broadcasts`, broadcast: (id: string) => `${RESEND_BASE}/broadcasts/${id}`, + documentation: `${RESEND_BASE}/docs`, } as const; diff --git a/tests/commands/docs.test.ts b/tests/commands/docs.test.ts new file mode 100644 index 0000000..58b9b1a --- /dev/null +++ b/tests/commands/docs.test.ts @@ -0,0 +1,24 @@ +import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; +import * as browser from '../../src/lib/browser'; + +describe('resend docs command', () => { + beforeEach(() => { + vi.spyOn(browser, 'openInBrowserOrLog').mockResolvedValue(); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + test('opens documentation URL in browser', async () => { + const { docsCommand } = await import('../../src/commands/docs'); + + await docsCommand.parseAsync([], { from: 'user' }); + + expect(browser.openInBrowserOrLog).toHaveBeenCalledTimes(1); + expect(browser.openInBrowserOrLog).toHaveBeenCalledWith( + browser.RESEND_URLS.documentation, + expect.any(Object), + ); + }); +});