mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-18 18:04:26 +00:00
fix: suppress all stdout pollution in --json mode across all commands
- update: emit JSON on empty skills, gate warn/console.log on !json - remove: emit JSON on empty results, gate warn/log on !json - find: gate step() calls on !json - install: emit JSON error object in catch block instead of console.log
This commit is contained in:
@@ -121,7 +121,7 @@ export class FindCommand extends Command {
|
||||
)
|
||||
.slice(0, limit);
|
||||
|
||||
if (!this.quiet) {
|
||||
if (!this.quiet && !this.json) {
|
||||
step("Showing featured skills");
|
||||
}
|
||||
} else if (this.query) {
|
||||
@@ -142,7 +142,7 @@ export class FindCommand extends Command {
|
||||
|
||||
s.stop(`Found ${results.length} skill(s)`);
|
||||
} else {
|
||||
if (!this.quiet) {
|
||||
if (!this.quiet && !this.json) {
|
||||
step("Enter a search term or browse featured skills");
|
||||
}
|
||||
|
||||
|
||||
@@ -186,8 +186,12 @@ export class InstallCommand extends Command {
|
||||
|
||||
return 0;
|
||||
} catch (err) {
|
||||
s.stop(colors.error("Installation failed"));
|
||||
console.log(colors.muted(err instanceof Error ? err.message : String(err)));
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({ success: false, error: err instanceof Error ? err.message : String(err) }));
|
||||
} else {
|
||||
s.stop(colors.error("Installation failed"));
|
||||
console.log(colors.muted(err instanceof Error ? err.message : String(err)));
|
||||
}
|
||||
return 1;
|
||||
} finally {
|
||||
if (cloneResult) this.cleanupTemp(cloneResult);
|
||||
|
||||
@@ -55,22 +55,30 @@ export class RemoveCommand extends Command {
|
||||
return meta?.source?.includes(this.source!) ?? false;
|
||||
}).map((s) => ({ name: s.name, path: s.path }));
|
||||
if (skillsToRemove.length === 0) {
|
||||
warn(`No skills found from source: ${this.source}`);
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({ success: true, removed: [], failed: [], total: 0 }));
|
||||
} else {
|
||||
warn(`No skills found from source: ${this.source}`);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
skillsToRemove = allSkills.map((s) => ({ name: s.name, path: s.path }));
|
||||
if (skillsToRemove.length === 0) {
|
||||
warn('No installed skills found');
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({ success: true, removed: [], failed: [], total: 0 }));
|
||||
} else {
|
||||
warn('No installed skills found');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
console.log(colors.muted(`Found ${skillsToRemove.length} skill(s) to remove`));
|
||||
if (!this.json) console.log(colors.muted(`Found ${skillsToRemove.length} skill(s) to remove`));
|
||||
} else {
|
||||
for (const skillName of this.skills) {
|
||||
const skill = findSkill(skillName, searchDirs);
|
||||
if (!skill) {
|
||||
warn(`Skill not found: ${skillName}`);
|
||||
if (!this.json) warn(`Skill not found: ${skillName}`);
|
||||
continue;
|
||||
}
|
||||
skillsToRemove.push({ name: skill.name, path: skill.path });
|
||||
|
||||
@@ -39,7 +39,7 @@ export class UpdateCommand extends Command {
|
||||
.filter((s): s is NonNullable<typeof s> => s !== null);
|
||||
|
||||
const notFound = this.skills.filter(name => !findSkill(name, searchDirs));
|
||||
if (notFound.length > 0) {
|
||||
if (notFound.length > 0 && !this.json) {
|
||||
warn(`Skills not found: ${notFound.join(', ')}`);
|
||||
}
|
||||
} else {
|
||||
@@ -47,7 +47,11 @@ export class UpdateCommand extends Command {
|
||||
}
|
||||
|
||||
if (skillsToUpdate.length === 0) {
|
||||
warn('No skills to update');
|
||||
if (this.json) {
|
||||
console.log(JSON.stringify({ updated: 0, skipped: 0, failed: 0 }));
|
||||
} else {
|
||||
warn('No skills to update');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,7 +65,7 @@ export class UpdateCommand extends Command {
|
||||
const metadata = loadSkillMetadata(skill.path);
|
||||
|
||||
if (!metadata) {
|
||||
console.log(colors.muted(`Skipping ${skill.name} (no metadata, reinstall needed)`));
|
||||
if (!this.json) console.log(colors.muted(`Skipping ${skill.name} (no metadata, reinstall needed)`));
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
@@ -176,7 +180,7 @@ export class UpdateCommand extends Command {
|
||||
}
|
||||
} catch (err) {
|
||||
s.stop(colors.error(`Failed to update ${skill.name}`));
|
||||
console.log(colors.muted(err instanceof Error ? err.message : String(err)));
|
||||
if (!this.json) console.log(colors.muted(err instanceof Error ? err.message : String(err)));
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user