mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-18 18:04:26 +00:00
feat: add --json flag to 8 CLI commands for structured output (#89)
This commit is contained in:
@@ -52,11 +52,15 @@ export class CheckCommand extends Command {
|
||||
description: 'Minimal output',
|
||||
});
|
||||
|
||||
json = Option.Boolean('--json', false, {
|
||||
description: 'Output as JSON',
|
||||
});
|
||||
|
||||
async execute(): Promise<number> {
|
||||
const searchDirs = getSearchDirs();
|
||||
const s = spinner();
|
||||
|
||||
if (!this.quiet) {
|
||||
if (!this.quiet && !this.json) {
|
||||
header('Check Updates');
|
||||
}
|
||||
|
||||
@@ -85,7 +89,7 @@ export class CheckCommand extends Command {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!this.quiet) {
|
||||
if (!this.quiet && !this.json) {
|
||||
step(`Checking ${skillsToCheck.length} skill(s) for updates...`);
|
||||
console.log('');
|
||||
}
|
||||
@@ -195,6 +199,19 @@ export class CheckCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({
|
||||
skills: results.map((r) => ({
|
||||
name: r.name,
|
||||
hasUpdate: r.hasUpdate,
|
||||
quality: r.qualityScore ?? null,
|
||||
stars: r.stars ?? null,
|
||||
})),
|
||||
updatesAvailable,
|
||||
}));
|
||||
return 0;
|
||||
}
|
||||
|
||||
console.log('');
|
||||
|
||||
const withUpdates = results.filter(r => r.hasUpdate);
|
||||
|
||||
@@ -65,11 +65,15 @@ export class FindCommand extends Command {
|
||||
hidden: true,
|
||||
});
|
||||
|
||||
json = Option.Boolean("--json", false, {
|
||||
description: "Output as JSON",
|
||||
});
|
||||
|
||||
async execute(): Promise<number> {
|
||||
const s = spinner();
|
||||
const limit = parseInt(this.limit, 10) || 10;
|
||||
|
||||
if (!this.quiet) {
|
||||
if (!this.quiet && !this.json) {
|
||||
header("Find Skills");
|
||||
}
|
||||
|
||||
@@ -252,6 +256,18 @@ export class FindCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({
|
||||
results: results.map((r) => ({
|
||||
name: r.name,
|
||||
description: r.description || "",
|
||||
source: r.source,
|
||||
})),
|
||||
total: results.length,
|
||||
}));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (results.length === 0) {
|
||||
console.log(colors.muted("No skills found matching your search"));
|
||||
console.log("");
|
||||
|
||||
@@ -133,14 +133,18 @@ export class InstallCommand extends Command {
|
||||
description: "Run security scan before installing (default: true)",
|
||||
});
|
||||
|
||||
json = Option.Boolean("--json", false, {
|
||||
description: "Output as JSON",
|
||||
});
|
||||
|
||||
async execute(): Promise<number> {
|
||||
const isInteractive =
|
||||
process.stdin.isTTY && !this.skills && !this.all && !this.yes;
|
||||
process.stdin.isTTY && !this.skills && !this.all && !this.yes && !this.json;
|
||||
const s = spinner();
|
||||
let cloneResult: Awaited<ReturnType<typeof this.resolveSource>>["cloneResult"] = null;
|
||||
|
||||
try {
|
||||
if (process.stdin.isTTY && !this.quiet) {
|
||||
if (process.stdin.isTTY && !this.quiet && !this.json) {
|
||||
welcome();
|
||||
}
|
||||
|
||||
@@ -657,6 +661,16 @@ export class InstallCommand extends Command {
|
||||
providerAdapter: ReturnType<typeof detectProvider>,
|
||||
isInteractive: boolean,
|
||||
): Promise<void> {
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({
|
||||
success: true,
|
||||
installed: installResults.map((r) => r.skillName),
|
||||
agents: targetAgents,
|
||||
total: installResults.length,
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
if (installResults.length > 0) {
|
||||
if (isInteractive) {
|
||||
showInstallSummary({
|
||||
|
||||
@@ -59,7 +59,14 @@ export class ListCommand extends Command {
|
||||
: skills.map(s => ({ ...s, quality: null as number | null }));
|
||||
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify(skillsWithQuality, null, 2));
|
||||
console.log(JSON.stringify({
|
||||
skills: skillsWithQuality.map((s) => ({
|
||||
name: s.name,
|
||||
enabled: s.enabled,
|
||||
path: s.path,
|
||||
})),
|
||||
total: skillsWithQuality.length,
|
||||
}));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -453,6 +453,10 @@ export class PublishSubmitCommand extends Command {
|
||||
description: "Show what would be submitted",
|
||||
});
|
||||
|
||||
json = Option.Boolean("--json", false, {
|
||||
description: "Output as JSON",
|
||||
});
|
||||
|
||||
async execute(): Promise<number> {
|
||||
const skillPath = this.skillPath || process.cwd();
|
||||
const skillMdPath = this.findSkillMd(skillPath);
|
||||
@@ -465,7 +469,7 @@ export class PublishSubmitCommand extends Command {
|
||||
return 1;
|
||||
}
|
||||
|
||||
step("Submitting skill to SkillKit marketplace...\n");
|
||||
if (!this.json) step("Submitting skill to SkillKit marketplace...\n");
|
||||
|
||||
const content = readFileSync(skillMdPath, "utf-8");
|
||||
const frontmatter = this.parseFrontmatter(content);
|
||||
@@ -508,26 +512,28 @@ export class PublishSubmitCommand extends Command {
|
||||
tags: frontmatter.tags || ["general"],
|
||||
};
|
||||
|
||||
console.log(colors.primary("Skill details:"));
|
||||
console.log(colors.muted(` ID: ${skillEntry.id}`));
|
||||
console.log(colors.muted(` Name: ${skillEntry.name}`));
|
||||
console.log(colors.muted(` Description: ${skillEntry.description}`));
|
||||
console.log(colors.muted(` Source: ${skillEntry.source}`));
|
||||
console.log(colors.muted(` Tags: ${skillEntry.tags.join(", ")}`));
|
||||
console.log(colors.muted(` Quality: ${qualityBadge}${qualityScore !== null ? ` (${qualityScore}/100)` : ""}`));
|
||||
if (activity) {
|
||||
const stars = formatCount(activity.stars);
|
||||
const pushed = activity.pushedAt ? timeAgo(activity.pushedAt) : "unknown";
|
||||
console.log(colors.muted(` Stars: ${stars}`));
|
||||
console.log(colors.muted(` Last push: ${pushed}`));
|
||||
}
|
||||
if (quality && quality.warnings.length > 0) {
|
||||
console.log(colors.warning(` Warnings:`));
|
||||
for (const w of quality.warnings.slice(0, 3)) {
|
||||
console.log(colors.muted(` - ${w}`));
|
||||
if (!this.json) {
|
||||
console.log(colors.primary("Skill details:"));
|
||||
console.log(colors.muted(` ID: ${skillEntry.id}`));
|
||||
console.log(colors.muted(` Name: ${skillEntry.name}`));
|
||||
console.log(colors.muted(` Description: ${skillEntry.description}`));
|
||||
console.log(colors.muted(` Source: ${skillEntry.source}`));
|
||||
console.log(colors.muted(` Tags: ${skillEntry.tags.join(", ")}`));
|
||||
console.log(colors.muted(` Quality: ${qualityBadge}${qualityScore !== null ? ` (${qualityScore}/100)` : ""}`));
|
||||
if (activity) {
|
||||
const stars = formatCount(activity.stars);
|
||||
const pushed = activity.pushedAt ? timeAgo(activity.pushedAt) : "unknown";
|
||||
console.log(colors.muted(` Stars: ${stars}`));
|
||||
console.log(colors.muted(` Last push: ${pushed}`));
|
||||
}
|
||||
if (quality && quality.warnings.length > 0) {
|
||||
console.log(colors.warning(` Warnings:`));
|
||||
for (const w of quality.warnings.slice(0, 3)) {
|
||||
console.log(colors.muted(` - ${w}`));
|
||||
}
|
||||
}
|
||||
console.log();
|
||||
}
|
||||
console.log();
|
||||
|
||||
if (this.dryRun) {
|
||||
warn("Dry run - not submitting");
|
||||
@@ -566,6 +572,15 @@ export class PublishSubmitCommand extends Command {
|
||||
},
|
||||
).trim();
|
||||
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({
|
||||
success: true,
|
||||
source: `${repoInfo.owner}/${repoInfo.repo}`,
|
||||
quality: qualityScore,
|
||||
issueUrl: result || "",
|
||||
}));
|
||||
return 0;
|
||||
}
|
||||
success("Submission created!");
|
||||
if (result) {
|
||||
console.log(colors.muted(` ${result}`));
|
||||
|
||||
@@ -33,6 +33,10 @@ export class RemoveCommand extends Command {
|
||||
description: 'Skip confirmation',
|
||||
});
|
||||
|
||||
json = Option.Boolean('--json', false, {
|
||||
description: 'Output as JSON',
|
||||
});
|
||||
|
||||
async execute(): Promise<number> {
|
||||
const searchDirs = getSearchDirs();
|
||||
|
||||
@@ -75,6 +79,8 @@ export class RemoveCommand extends Command {
|
||||
|
||||
let removed = 0;
|
||||
let failed = 0;
|
||||
const removedNames: string[] = [];
|
||||
const failedNames: string[] = [];
|
||||
|
||||
for (const { name: skillName, path: skillPath } of skillsToRemove) {
|
||||
if (!existsSync(skillPath)) {
|
||||
@@ -89,15 +95,29 @@ export class RemoveCommand extends Command {
|
||||
if (existsSync(metaSibling)) rmSync(metaSibling);
|
||||
}
|
||||
removeSkillFromLock(skillName);
|
||||
success(`Removed: ${skillName}`);
|
||||
removedNames.push(skillName);
|
||||
if (!this.json) success(`Removed: ${skillName}`);
|
||||
removed++;
|
||||
} catch (err) {
|
||||
error(`Failed to remove: ${skillName}`);
|
||||
console.error(colors.muted(err instanceof Error ? err.message : String(err)));
|
||||
failedNames.push(skillName);
|
||||
if (!this.json) {
|
||||
error(`Failed to remove: ${skillName}`);
|
||||
console.error(colors.muted(err instanceof Error ? err.message : String(err)));
|
||||
}
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({
|
||||
success: failed === 0,
|
||||
removed: removedNames,
|
||||
failed: failedNames,
|
||||
total: removed + failed,
|
||||
}));
|
||||
return failed > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
if (removed > 0) {
|
||||
try {
|
||||
const agentsMdPath = join(process.cwd(), 'AGENTS.md');
|
||||
|
||||
@@ -47,6 +47,10 @@ export class ScanCommand extends Command {
|
||||
description: 'Comma-separated rule IDs or categories to skip',
|
||||
});
|
||||
|
||||
json = Option.Boolean('--json', false, {
|
||||
description: 'Output as JSON',
|
||||
});
|
||||
|
||||
async execute(): Promise<number> {
|
||||
const targetPath = resolve(this.skillPath);
|
||||
|
||||
@@ -79,6 +83,11 @@ export class ScanCommand extends Command {
|
||||
|
||||
const result = await scanner.scan(targetPath);
|
||||
|
||||
if (this.json) {
|
||||
this.context.stdout.write(formatResult(result, 'json') + '\n');
|
||||
return result.verdict === 'fail' ? 1 : 0;
|
||||
}
|
||||
|
||||
this.context.stdout.write(formatResult(result, this.format) + '\n');
|
||||
|
||||
return result.verdict === 'fail' ? 1 : 0;
|
||||
|
||||
@@ -23,6 +23,10 @@ export class UpdateCommand extends Command {
|
||||
description: 'Force update even if local changes exist',
|
||||
});
|
||||
|
||||
json = Option.Boolean('--json', false, {
|
||||
description: 'Output as JSON',
|
||||
});
|
||||
|
||||
async execute(): Promise<number> {
|
||||
const s = spinner();
|
||||
const searchDirs = getSearchDirs();
|
||||
@@ -177,6 +181,11 @@ export class UpdateCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({ updated, skipped, failed }));
|
||||
return failed > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
console.log();
|
||||
step(`Updated: ${updated}, Skipped: ${skipped}, Failed: ${failed}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user