add-parent-command

Create a Cobra parent command that groups subcommands and validates arguments.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Organize CLI tools by introducing a parent command that groups related subcommands under a single namespace.

Core Features & Use Cases

  • Provides a reusable pattern to scaffold a hierarchical Cobra-based CLI, with a dedicated parent command and multiple subcommands.
  • Demonstrates argument validation to prevent unknown subcommands and ensures the parent command displays helpful usage when invoked without a subcommand.
  • Guides integration with a root command and systematic registration of subcommands via AddCommand for scalable command organization.

Quick Start

Create a new parent command function, attach each subcommand with AddCommand, and ensure RunE returns help for the parent when no subcommand is provided.

Frequently Asked Questions about add-parent-command

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

FAQPage Schema
How do I group related Cobra subcommands under a single parent command in Go?

To group related Cobra subcommands, you create a parent command function and register each subcommand using AddCommand, establishing a single namespace for better discoverability and consistency across your Go CLI tool.

How do I make a Cobra parent command display help when no subcommand is provided?

To display help when no subcommand is provided, implement RunE-based help behavior in your parent command, ensuring it returns helpful usage information and validates arguments to prevent unknown subcommands from executing silently.

What is the best way to organize a growing CLI with multiple subcommands in Golang?

The best way to organize a growing Golang CLI is scaffolding a hierarchical command structure with a dedicated parent command, grouping related operations like list, remove, and init under a single namespace to improve discoverability and consistency.

Does this command organization pattern require explicit subcommand registration in Cobra?

Yes, this pattern requires explicit subcommand registration via AddCommand in Cobra, using patterns like New<Parent>Cmd to systematically attach subcommands to the parent command for scalable command organization.

How do I validate arguments and prevent unknown subcommands in a Cobra CLI?

To validate arguments and prevent unknown subcommands in a Cobra CLI, apply argument validation within the parent command structure, enforcing RunE-based behavior to catch invalid inputs and guide users toward correct usage.