|
| 1 | +/** |
| 2 | + * Feedback Command |
| 3 | + * |
| 4 | + * Allows users to submit feedback about the CLI. |
| 5 | + * All arguments after 'feedback' are joined into a single message. |
| 6 | + * |
| 7 | + * @example sentry feedback i love this tool |
| 8 | + * @example sentry feedback the issue view is confusing |
| 9 | + */ |
| 10 | + |
| 11 | +// biome-ignore lint/performance/noNamespaceImport: Sentry SDK recommends namespace import |
| 12 | +import * as Sentry from "@sentry/bun"; |
| 13 | +import { buildCommand } from "@stricli/core"; |
| 14 | +import type { SentryContext } from "../context.js"; |
| 15 | +import { ValidationError } from "../lib/errors.js"; |
| 16 | + |
| 17 | +export const feedbackCommand = buildCommand({ |
| 18 | + docs: { |
| 19 | + brief: "Send feedback about the CLI", |
| 20 | + fullDescription: |
| 21 | + "Submit feedback about your experience with the Sentry CLI. " + |
| 22 | + "All text after 'feedback' is sent as your message.", |
| 23 | + }, |
| 24 | + parameters: { |
| 25 | + flags: {}, |
| 26 | + positional: { |
| 27 | + kind: "array", |
| 28 | + parameter: { |
| 29 | + brief: "Your feedback message", |
| 30 | + parse: String, |
| 31 | + placeholder: "message", |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + // biome-ignore lint/complexity/noBannedTypes: Stricli requires empty object for commands with no flags |
| 36 | + async func(this: SentryContext, _flags: {}, ...messageParts: string[]) { |
| 37 | + const { stdout, stderr } = this; |
| 38 | + const message = messageParts.join(" "); |
| 39 | + |
| 40 | + if (!message.trim()) { |
| 41 | + throw new ValidationError("Please provide a feedback message."); |
| 42 | + } |
| 43 | + |
| 44 | + if (!Sentry.isEnabled()) { |
| 45 | + stderr.write("Feedback not sent: telemetry is disabled.\n"); |
| 46 | + stderr.write("Unset SENTRY_CLI_NO_TELEMETRY to enable feedback.\n"); |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + Sentry.captureFeedback({ message }); |
| 51 | + |
| 52 | + // Flush to ensure feedback is sent before process exits |
| 53 | + const sent = await Sentry.flush(3000); |
| 54 | + |
| 55 | + if (sent) { |
| 56 | + stdout.write("Feedback submitted. Thank you!\n"); |
| 57 | + } else { |
| 58 | + stderr.write("Feedback may not have been sent (network timeout).\n"); |
| 59 | + } |
| 60 | + }, |
| 61 | +}); |
0 commit comments