Documentation
¶
Index ¶
- func Initialize(cmd *cobra.Command, options *Options) error
- func Write(documentation Documentation) error
- type Command
- type Documentation
- type Flag
- type Formats
- type Logger
- type MarshalFn
- type Options
- func (o *Options) DisableUserCommandOptions() *Options
- func (o *Options) TemplateOptions() TemplateOptions
- func (o *Options) WithCommandName(name string) *Options
- func (o *Options) WithCustomTemplates(fs fs.FS) *Options
- func (o *Options) WithFormats(formats Formats) *Options
- func (o *Options) WithJsonMarshal(fn MarshalFn) *Options
- func (o *Options) WithLogger(logger Logger) *Options
- func (o *Options) WithMaxOptionWidthInMarkdown(width int) *Options
- func (o *Options) WithOutDirectory(out string) *Options
- func (o *Options) WithShowHiddenCommands() *Options
- func (o *Options) WithStripAnsiInMarkdown() *Options
- func (o *Options) WithYamlMarshal(fn MarshalFn) *Options
- type ParentCommand
- type TemplateOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Initialize ¶
Initialize a new documentation command with cmd as the parent, providing options for customization The provided command will always provide documentation from the *root*, which allows the caller to list this automated command under other administrative/tooling/hidden commands as needed.
func Write ¶
func Write(documentation Documentation) error
Write to outDir the documentation for all given formats
Types ¶
type Command ¶
type Command struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Usage string `yaml:"usage,omitempty" json:"usage,omitempty"`
Aliases []string `yaml:"aliases,omitempty" json:"aliases,omitempty"`
SuggestFor []string `yaml:"suggestFor,omitempty" json:"suggestFor,omitempty"`
Short string `yaml:"short,omitempty" json:"short,omitempty"`
Long string `yaml:"long,omitempty" json:"long,omitempty"`
GroupID string `yaml:"groupID,omitempty" json:"groupID,omitempty"`
ValidArgs []string `yaml:"validArgs,omitempty" json:"validArgs,omitempty"`
ArgAliases []string `yaml:"argAliases,omitempty" json:"argAliases,omitempty"`
Deprecated string `yaml:"deprecated,omitempty" json:"deprecated,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty" json:"annotations,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
Hidden bool `yaml:"hidden" json:"hidden"`
Runnable bool `yaml:"runnable" json:"runnable"`
RawFlagUsages string `yaml:"rawFlagUsages,omitempty" json:"rawFlagUsages,omitempty"`
Parent *ParentCommand `yaml:"parent,omitempty" json:"parent,omitempty"`
Subcommands []Command `yaml:"subcommands,omitempty" json:"subcommands,omitempty"`
LocalFlags []Flag `yaml:"localFlags,omitempty" json:"localFlags,omitempty"`
InheritedFlags []Flag `yaml:"inheritedFlags,omitempty" json:"inheritedFlags,omitempty"`
PersistentFlags []Flag `yaml:"persistentFlags,omitempty" json:"persistentFlags,omitempty"`
Examples []string `yaml:"examples,omitempty" json:"examples,omitempty"`
FullPath string `yaml:"fullPath,omitempty" json:"fullPath,omitempty"`
}
Command is a different representation of cobra.Command
type Documentation ¶
type Documentation struct {
GenerationDate string `yaml:"generationDate,omitempty" json:"generationDate,omitempty"`
AutoGenerationTag string `yaml:"autoGenerationTag,omitempty" json:"autoGenerationTag,omitempty"`
RootCommand Command `yaml:"rootCommand,omitempty" json:"rootCommand,omitempty"`
// contains filtered or unexported fields
}
Documentation represents the "top-level" of documentation to be passed to a template
func NewDocumentation ¶ added in v0.0.3
func NewDocumentation(cmd *cobra.Command, options *Options) Documentation
func (*Documentation) Write ¶ added in v0.0.3
func (d *Documentation) Write() error
Write these docs
type Flag ¶
type Flag struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Shorthand string `json:"shorthand,omitempty" yaml:"shorthand,omitempty"`
Usage string `json:"usage,omitempty" yaml:"usage,omitempty"`
DefValue string `json:"defValue,omitempty" yaml:"defValue,omitempty"`
NoOptDefVal string `json:"noOptDefVal,omitempty" yaml:"noOptDefVal,omitempty"`
Deprecated string `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
Hidden bool `json:"hidden,omitempty" yaml:"hidden,omitempty"`
ShorthandDeprecated string `json:"shorthandDeprecated,omitempty" yaml:"shorthandDeprecated,omitempty"`
Inherited bool `json:"inherited,omitempty" yaml:"inherited,omitempty"`
Persistent bool `json:"persistent,omitempty" yaml:"persistent,omitempty"`
Local bool `json:"local,omitempty" yaml:"local,omitempty"`
RawUsage string `json:"rawUsage,omitempty" yaml:"rawUsage,omitempty"`
}
Flag is a representation of pflag.Flag
type Formats ¶
type Formats byte
Formats defines the flag of supported documentation formats
const ( // Markdown will result in Markdown/CommonMark style output Markdown Formats = 1 << iota // Man will result in manpage format Man // Yaml will result in the YAML 1.1+ format Yaml // ReST will result in Restructured Text format ReST // Json will result in JavaScript Object Notation (JSON) format Json )
func (*Formats) IsValid ¶
IsValid determines if this set of Formats flags are valid; anything set but not defined in the Formats flag set will return false.
type Logger ¶
type Logger interface {
// Printf is a common signature used by log.Logger, logrus.Logger, and others
Printf(format string, v ...any)
}
Logger allows the user to provide any logger fulfilling this interface
type MarshalFn ¶
MarshalFn is a common interface allowing the caller to provide yaml/json marshaller functions
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options provides a builder-pattern of user-facing optional functionality when constructing via venom.Initialize
func NewOptions ¶
func NewOptions() *Options
NewOptions provides a new set of options with default command name ("docs") and formats (Markdown). The value returned here follows the builder pattern for easily discovering and applying available options.
func (*Options) DisableUserCommandOptions ¶ added in v0.0.2
DisableUserCommandOptions allows the caller to define fixed options such as output directory, supported doc formats, etc. Default behavior is a documentation command which provides defaults defined by the caller, but exposing a subset of options to the user.
func (*Options) TemplateOptions ¶
func (o *Options) TemplateOptions() TemplateOptions
TemplateOptions provides the value of current TemplateOptions
func (*Options) WithCommandName ¶
WithCommandName allows the caller to provide the target command name, which is used to construct a cobra.Command for documentation.
func (*Options) WithCustomTemplates ¶ added in v0.0.3
WithCustomTemplates allows the user to provide an implementation which provide custom templates for any template-driven format.
func (*Options) WithFormats ¶
WithFormats allows the caller to define formats which differ from the Options defaults.
func (*Options) WithJsonMarshal ¶
WithJsonMarshal allows the caller to define a custom JSON marshaling function, default is json.Marshal from the Go standard library.
func (*Options) WithLogger ¶
WithLogger allows the caller to define a target log implementation for any warnings or errors from the initialized command.
func (*Options) WithMaxOptionWidthInMarkdown ¶ added in v0.0.8
func (*Options) WithOutDirectory ¶
WithOutDirectory allows the caller to define an output directory which differs from the default ./docs.
func (*Options) WithShowHiddenCommands ¶
WithShowHiddenCommands allows the caller to signify whether details about hidden commands should be present in the final output
func (*Options) WithStripAnsiInMarkdown ¶ added in v0.0.2
WithStripAnsiInMarkdown allows the caller to require ANSI characters to be stripped when processing markdown files.
func (*Options) WithYamlMarshal ¶
WithYamlMarshal allows the caller to define a custom YAML marshaling function, default is yaml.Marshal (v3) as depended by cobra.
type ParentCommand ¶
type ParentCommand struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Short string `yaml:"short,omitempty" json:"short,omitempty"`
FullPath string `yaml:"fullPath,omitempty" json:"fullPath,omitempty"`
}
ParentCommand provides the name of a command's parent