# Extension points — spf13/cobra

> Canonical page: https://codevetter.com/unpack/cobra/extension-points

# Extension points — spf13/cobra

Scanned commit adbc8813901bba65827259daa8e22ff94ec1f30e (2026-07-10). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Extension uses ordinary Go values, callbacks, and metadata rather than requiring a special constructor. Command composition defines new actions and hierarchies. Registration APIs customize completion, validation, templates, lifecycle behavior, and generated documentation. Compatibility APIs include both supported extension surfaces and explicitly disabled legacy methods.
- Applications instantiate Command directly and register children through AddCommand, which assigns parents, propagates normalization, and invalidates command sorting. — [site/content/user_guide.md#L39-54](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/site/content/user_guide.md#L39-L54) [command.go#L1342-1367](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/command.go#L1342-L1367)
- Run/RunE and persistent/local pre/post callback fields provide action and lifecycle extension points; error-returning variants take precedence when both forms are defined. — [command.go#L123-151](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/command.go#L123-L151) [command.go#L984-1041](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/command.go#L984-L1041)
- PositionalArgs is a function type; MatchAll builds a validator that runs supplied validators in order and returns the first error. — [args.go#L22-22](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/args.go#L22-L22) [args.go#L126-135](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/args.go#L126-L135)
- RegisterFlagCompletionFunc keys callbacks by the resolved pflag.Flag pointer, rejects missing or already-registered flags, and complements command-level ValidArgsFunction. — [completions.go#L170-195](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/completions.go#L170-L195) [completions.go#L567-581](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/completions.go#L567-L581)
- Flag annotations plug into required-flag, filename, directory, and legacy Bash custom completion behavior; portable Go callbacks are recommended over MarkFlagCustom. — [shell_completions.go#L35-55](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/shell_completions.go#L35-L55) [shell_completions.go#L65-97](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/shell_completions.go#L65-L97)
- SetHelpFunc, SetUsageFunc, template setters, and AddTemplateFunc customize inherited help/usage behavior and template function lookup. — [command.go#L313-338](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/command.go#L313-L338) [command.go#L444-472](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/command.go#L444-L472) [command.go#L484-514](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/command.go#L484-L514) [cobra.go#L83-94](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/cobra.go#L83-L94)
- CommandDisplayNameAnnotation adapts displayed identity for external plugins such as kubectl-myplugin presented as kubectl myplugin; DisplayName reads this metadata. — [site/content/user_guide.md#L835-868](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/site/content/user_guide.md#L835-L868) [command.go#L1472-1478](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/command.go#L1472-L1478)
- Documentation custom APIs accept link handlers and file prependers; GenManTreeOptions adds output path and command separator, while GenManHeader supplies title, section, date, source, and manual. — [doc/md_docs.go#L131-155](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/doc/md_docs.go#L131-L155) [doc/rest_docs.go#L143-166](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/doc/rest_docs.go#L143-L166) [doc/man_docs.go#L81-97](https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/doc/man_docs.go#L81-L97)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
