Skip to content

Commit a40fe63

Browse files
committed
feat(cli): add badge command for generating Markdown badges
1 parent 45fbb9d commit a40fe63

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

bin/cli.mjs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const flags = {
1313
help: false,
1414
version: false,
1515
noInteractive: false,
16+
badge: false,
1617
};
1718
let targetPath = '.';
1819

@@ -22,12 +23,13 @@ for (const arg of args) {
2223
else if (arg === '--help' || arg === '-h') flags.help = true;
2324
else if (arg === '--version') flags.version = true;
2425
else if (arg === '--no-interactive' || arg === '--ci') flags.noInteractive = true;
26+
else if (arg === 'badge') flags.badge = true;
2527
else if (!arg.startsWith('-')) targetPath = arg;
2628
}
2729

2830
// Auto-detect: disable interactive when piped or in CI
2931
const isTTY = process.stdout.isTTY && !process.env.CI;
30-
const interactive = isTTY && !flags.json && !flags.noInteractive;
32+
const interactive = isTTY && !flags.json && !flags.noInteractive && !flags.badge;
3133

3234
// ── Help ──────────────────────────────────────────────────
3335
if (flags.help) {
@@ -37,6 +39,9 @@ if (flags.help) {
3739
Usage
3840
$ check-ai [directory] [options]
3941
42+
Commands
43+
badge Generate a shields.io badge in Markdown
44+
4045
Options
4146
--json Output results as JSON
4247
--verbose, -v Show all recommendations (including low-priority)
@@ -50,6 +55,7 @@ if (flags.help) {
5055
$ check-ai ./my-project # audit a specific repo
5156
$ check-ai --json # machine-readable output
5257
$ check-ai . --verbose # include nice-to-have suggestions
58+
$ check-ai badge # output a Markdown badge
5359
`);
5460
process.exit(0);
5561
}
@@ -75,7 +81,7 @@ if (interactive) {
7581
console.log('');
7682
spinner = createSpinner();
7783
spinner.start(`Auditing ${repoName} …`);
78-
} else if (!flags.json) {
84+
} else if (!flags.json && !flags.badge) {
7985
console.log('');
8086
console.log(` 🔍 Auditing ${repoName} …`);
8187
}
@@ -100,7 +106,13 @@ const onProgress = interactive
100106
const findings = await scan(targetDir, onProgress);
101107
const result = score(findings);
102108

103-
if (flags.json) {
109+
if (flags.badge) {
110+
const badgeColor = result.color === 'green' ? 'brightgreen' : result.color === 'yellow' ? 'yellow' : 'red';
111+
const label = 'AI Ready';
112+
const message = `${result.grade} ${result.normalized}/10`;
113+
const url = `https://img.shields.io/badge/${encodeURIComponent(label)}-${encodeURIComponent(message)}-${badgeColor}`;
114+
console.log(`[![AI Ready](${url})](https://github.com/f/check-ai)`);
115+
} else if (flags.json) {
104116
reportJson(result, findings);
105117
} else if (interactive) {
106118
await reportInteractive(result, findings, { verbose: flags.verbose });

0 commit comments

Comments
 (0)