Skip to content

Commit dc3401a

Browse files
committed
refactor(formatters): extract features formatting helper (DRY)
- Add formatFeaturesList() helper to eliminate duplicated features formatting - Add MAX_DISPLAY_FEATURES constant for configurable truncation limit - Improve JSDoc on writeHumanOutput helpers in org/project get commands
1 parent 418b009 commit dc3401a

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

packages/cli/src/commands/org/get.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ type GetFlags = {
1717

1818
/**
1919
* Write human-readable organization output to stdout.
20+
*
21+
* @param stdout - Stream to write formatted output
22+
* @param org - Organization data to display
23+
* @param detectedFrom - Optional source description if org was auto-detected
2024
*/
2125
function writeHumanOutput(
2226
stdout: NodeJS.WriteStream,

packages/cli/src/commands/project/get.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type GetFlags = {
1818

1919
/**
2020
* 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
2125
*/
2226
function writeHumanOutput(
2327
stdout: NodeJS.WriteStream,

packages/cli/src/lib/formatters/human.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ const STATUS_LABELS: Record<IssueStatus, string> = {
3030
ignored: "− Ignored",
3131
};
3232

33+
/** Maximum features to display before truncating with "... and N more" */
34+
const MAX_DISPLAY_FEATURES = 10;
35+
36+
/**
37+
* Format a features array for display, truncating if necessary.
38+
*
39+
* @param features - Array of feature names (may be undefined)
40+
* @returns Formatted lines to append to output, or empty array if no features
41+
*/
42+
function formatFeaturesList(features: string[] | undefined): string[] {
43+
if (!features || features.length === 0) {
44+
return [];
45+
}
46+
47+
const lines: string[] = ["", `Features (${features.length}):`];
48+
const displayFeatures = features.slice(0, MAX_DISPLAY_FEATURES);
49+
lines.push(` ${displayFeatures.join(", ")}`);
50+
51+
if (features.length > MAX_DISPLAY_FEATURES) {
52+
lines.push(` ... and ${features.length - MAX_DISPLAY_FEATURES} more`);
53+
}
54+
55+
return lines;
56+
}
57+
3358
/**
3459
* Get status icon for an issue status
3560
*/
@@ -283,16 +308,7 @@ export function formatOrgDetails(org: SentryOrganization): string[] {
283308
lines.push(`Early Adopter: ${org.isEarlyAdopter ? "Yes" : "No"}`);
284309

285310
// Features
286-
if (org.features && org.features.length > 0) {
287-
lines.push("");
288-
lines.push(`Features (${org.features.length}):`);
289-
const maxFeatures = 10;
290-
const displayFeatures = org.features.slice(0, maxFeatures);
291-
lines.push(` ${displayFeatures.join(", ")}`);
292-
if (org.features.length > maxFeatures) {
293-
lines.push(` ... and ${org.features.length - maxFeatures} more`);
294-
}
295-
}
311+
lines.push(...formatFeaturesList(org.features));
296312

297313
return lines;
298314
}
@@ -386,16 +402,7 @@ export function formatProjectDetails(project: SentryProject): string[] {
386402
lines.push(` Monitors: ${project.hasMonitors ? "Yes" : "No"}`);
387403

388404
// Features
389-
if (project.features && project.features.length > 0) {
390-
lines.push("");
391-
lines.push(`Features (${project.features.length}):`);
392-
const maxFeatures = 10;
393-
const displayFeatures = project.features.slice(0, maxFeatures);
394-
lines.push(` ${displayFeatures.join(", ")}`);
395-
if (project.features.length > maxFeatures) {
396-
lines.push(` ... and ${project.features.length - maxFeatures} more`);
397-
}
398-
}
405+
lines.push(...formatFeaturesList(project.features));
399406

400407
return lines;
401408
}

0 commit comments

Comments
 (0)