[#578] gendoc: Allow to customize man pages

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-08-08 18:08:00 +03:00 committed by Evgenii Stratonikov
parent 082370583f
commit b02a1a34c1
4 changed files with 22 additions and 9 deletions

View file

@ -45,7 +45,7 @@ func init() {
rootCmd.AddCommand(storagecfg.RootCmd) rootCmd.AddCommand(storagecfg.RootCmd)
rootCmd.AddCommand(autocomplete.Command("frostfs-adm")) rootCmd.AddCommand(autocomplete.Command("frostfs-adm"))
rootCmd.AddCommand(gendoc.Command(rootCmd)) rootCmd.AddCommand(gendoc.Command(rootCmd, gendoc.Options{}))
} }
func Execute() error { func Execute() error {

View file

@ -85,7 +85,7 @@ func init() {
rootCmd.AddCommand(objectCli.Cmd) rootCmd.AddCommand(objectCli.Cmd)
rootCmd.AddCommand(containerCli.Cmd) rootCmd.AddCommand(containerCli.Cmd)
rootCmd.AddCommand(tree.Cmd) rootCmd.AddCommand(tree.Cmd)
rootCmd.AddCommand(gendoc.Command(rootCmd)) rootCmd.AddCommand(gendoc.Command(rootCmd, gendoc.Options{}))
} }
func entryPoint(cmd *cobra.Command, _ []string) { func entryPoint(cmd *cobra.Command, _ []string) {

View file

@ -38,7 +38,7 @@ func init() {
blobovnicza.Root, blobovnicza.Root,
meta.Root, meta.Root,
writecache.Root, writecache.Root,
gendoc.Command(command), gendoc.Command(command, gendoc.Options{}),
) )
} }

View file

@ -23,8 +23,25 @@ const (
extensionFlag = "extension" extensionFlag = "extension"
) )
// Options for doc generation.
type Options struct {
// Parameters for man generation. By default use (1) section and `FrostFS` source.
ManHeader *doc.GenManHeader
}
func (o *Options) fillDefaults() {
if o.ManHeader == nil {
o.ManHeader = &doc.GenManHeader{
Section: "1",
Source: "FrostFS",
}
}
}
// Command returns command which generates user documentation for the argument. // Command returns command which generates user documentation for the argument.
func Command(rootCmd *cobra.Command) *cobra.Command { func Command(rootCmd *cobra.Command, opts Options) *cobra.Command {
opts.fillDefaults()
gendocCmd := &cobra.Command{ gendocCmd := &cobra.Command{
Use: "gendoc <dir>", Use: "gendoc <dir>",
Short: "Generate documentation for this command", Short: "Generate documentation for this command",
@ -65,11 +82,7 @@ In this case there is a number of helper functions which can be used:
case gendocMarkdown: case gendocMarkdown:
return doc.GenMarkdownTree(rootCmd, args[0]) return doc.GenMarkdownTree(rootCmd, args[0])
case gendocMan: case gendocMan:
hdr := &doc.GenManHeader{ return doc.GenManTree(rootCmd, opts.ManHeader, args[0])
Section: "1",
Source: "FrostFS",
}
return doc.GenManTree(rootCmd, hdr, args[0])
default: default:
return errors.New("type must be 'md' or 'man'") return errors.New("type must be 'md' or 'man'")
} }