|
| 1 | +/** |
| 2 | + * sentry project get |
| 3 | + * |
| 4 | + * Get detailed information about a Sentry project. |
| 5 | + */ |
| 6 | + |
| 7 | +import { buildCommand } from "@stricli/core"; |
| 8 | +import type { SentryContext } from "../../context.js"; |
| 9 | +import { getProject } from "../../lib/api-client.js"; |
| 10 | +import { formatProjectDetails } from "../../lib/formatters/human.js"; |
| 11 | +import { writeJson } from "../../lib/formatters/json.js"; |
| 12 | +import { resolveOrgAndProject } from "../../lib/resolve-target.js"; |
| 13 | + |
| 14 | +type GetFlags = { |
| 15 | + readonly org?: string; |
| 16 | + readonly json: boolean; |
| 17 | +}; |
| 18 | + |
| 19 | +/** |
| 20 | + * Write human-readable project output to stdout. |
| 21 | + * |
| 22 | + * @param stdout - Stream to write formatted output |
| 23 | + * @param project - Project data to display |
| 24 | + * @param detectedFrom - Optional source description if project was auto-detected |
| 25 | + */ |
| 26 | +function writeHumanOutput( |
| 27 | + stdout: Writer, |
| 28 | + project: Parameters<typeof formatProjectDetails>[0], |
| 29 | + detectedFrom?: string |
| 30 | +): void { |
| 31 | + const lines = formatProjectDetails(project); |
| 32 | + stdout.write(`${lines.join("\n")}\n`); |
| 33 | + |
| 34 | + if (detectedFrom) { |
| 35 | + stdout.write(`\nDetected from ${detectedFrom}\n`); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +export const getCommand = buildCommand({ |
| 40 | + docs: { |
| 41 | + brief: "Get details of a project", |
| 42 | + fullDescription: |
| 43 | + "Retrieve detailed information about a Sentry project.\n\n" + |
| 44 | + "The organization and project are resolved from:\n" + |
| 45 | + " 1. Positional argument <project-slug> and --org flag\n" + |
| 46 | + " 2. Config defaults\n" + |
| 47 | + " 3. SENTRY_DSN environment variable or source code detection", |
| 48 | + }, |
| 49 | + parameters: { |
| 50 | + positional: { |
| 51 | + kind: "tuple", |
| 52 | + parameters: [ |
| 53 | + { |
| 54 | + brief: "Project slug (optional if auto-detected)", |
| 55 | + parse: String, |
| 56 | + optional: true, |
| 57 | + }, |
| 58 | + ], |
| 59 | + }, |
| 60 | + flags: { |
| 61 | + org: { |
| 62 | + kind: "parsed", |
| 63 | + parse: String, |
| 64 | + brief: "Organization slug", |
| 65 | + optional: true, |
| 66 | + }, |
| 67 | + json: { |
| 68 | + kind: "boolean", |
| 69 | + brief: "Output as JSON", |
| 70 | + default: false, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + async func( |
| 75 | + this: SentryContext, |
| 76 | + flags: GetFlags, |
| 77 | + projectSlug?: string |
| 78 | + ): Promise<void> { |
| 79 | + const { process, cwd } = this; |
| 80 | + const { stdout } = process; |
| 81 | + |
| 82 | + const resolved = await resolveOrgAndProject({ |
| 83 | + org: flags.org, |
| 84 | + project: projectSlug, |
| 85 | + cwd, |
| 86 | + }); |
| 87 | + |
| 88 | + if (!resolved) { |
| 89 | + throw new Error( |
| 90 | + "Organization and project are required.\n\n" + |
| 91 | + "Please specify them using:\n" + |
| 92 | + " sentry project get <project-slug> --org <org-slug>\n\n" + |
| 93 | + "Or set SENTRY_DSN environment variable for automatic detection." |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + const project = await getProject(resolved.org, resolved.project); |
| 98 | + |
| 99 | + if (flags.json) { |
| 100 | + writeJson(stdout, project); |
| 101 | + return; |
| 102 | + } |
| 103 | + |
| 104 | + writeHumanOutput(stdout, project, resolved.detectedFrom); |
| 105 | + }, |
| 106 | +}); |
0 commit comments