add-command-with-json

Scaffold Cobra CLI commands with JSON output and tests.

10|14|Updated Feb 26, 2026
One-click install
npx skills add https://github.com/openkaiden/kdn --skill add-command-with-json
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: add-command-with-json
Source: https://github.com/openkaiden/kdn/tree/main/.agents/skills/add-command-with-json
Command: npx skills add https://github.com/openkaiden/kdn --skill add-command-with-json

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Add a new CLI command with JSON output support to standardize how new commands are created and tested within the kdn CLI environment.

Core Features & Use Cases

  • Scaffold a Cobra-based command file at pkg/cmd/<command>.go with a Use, Short, Long, Example sections.
  • Wire the command into rootCmd for discovery and add tests for preRun and execution paths.
  • Generate JSON-mode output support and optional text output for progress logging and error handling.

Quick Start

Create the new command file at pkg/cmd/<command>.go, wire it into root.go, and write tests to exercise both standard and JSON outputs.

Frequently Asked Questions about add-command-with-json

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new Cobra command with JSON output in Golang?

You scaffold a new Cobra command file at pkg/cmd/<command>.go, wire it into rootCmd, and generate tests. The scaffolding includes Use, Short, Long, Args, PreRunE, RunE fields, flag binding with *Var variants, JSON-mode output, and test scaffolding for execution paths.

How do I scaffold a CLI command file and wire it into the root command?

Scaffolding a CLI command file creates the file at pkg/cmd/<command>.go and wires it into rootCmd for discovery. This ensures the new command is properly registered while generating tests that exercise both standard and JSON outputs.

What is the required structure for a Cobra-based command with flag binding?

The required structure for a Cobra-based command includes Use, Short, Long, Args, PreRunE, and RunE sections. It also implements flag binding with *Var variants and supports JSON-mode output alongside optional text output for progress logging.

How do I generate tests for a Cobra command's JSON and standard output?

Test scaffolding for a Cobra command generates cases that exercise both standard and JSON outputs. This verifies the preRun and execution paths function correctly when handling flag binding and JSON-mode output.

Can I add optional text output for progress logging alongside JSON output?

Yes, command scaffolding supports both JSON-mode output and optional text output. This allows you to generate JSON for structured data while using text output for progress logging and error handling.