From b02a1a34c130570c71b659a31018d48e12512280 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 8 Aug 2023 18:08:00 +0300 Subject: [PATCH] [#578] gendoc: Allow to customize man pages Signed-off-by: Evgenii Stratonikov --- cmd/frostfs-adm/internal/modules/root.go | 2 +- cmd/frostfs-cli/modules/root.go | 2 +- cmd/frostfs-lens/root.go | 2 +- pkg/util/gendoc/gendoc.go | 25 ++++++++++++++++++------ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/root.go b/cmd/frostfs-adm/internal/modules/root.go index fd1517f9..0fa0f7f6 100644 --- a/cmd/frostfs-adm/internal/modules/root.go +++ b/cmd/frostfs-adm/internal/modules/root.go @@ -45,7 +45,7 @@ func init() { rootCmd.AddCommand(storagecfg.RootCmd) rootCmd.AddCommand(autocomplete.Command("frostfs-adm")) - rootCmd.AddCommand(gendoc.Command(rootCmd)) + rootCmd.AddCommand(gendoc.Command(rootCmd, gendoc.Options{})) } func Execute() error { diff --git a/cmd/frostfs-cli/modules/root.go b/cmd/frostfs-cli/modules/root.go index 93513479..808bd6d0 100644 --- a/cmd/frostfs-cli/modules/root.go +++ b/cmd/frostfs-cli/modules/root.go @@ -85,7 +85,7 @@ func init() { rootCmd.AddCommand(objectCli.Cmd) rootCmd.AddCommand(containerCli.Cmd) rootCmd.AddCommand(tree.Cmd) - rootCmd.AddCommand(gendoc.Command(rootCmd)) + rootCmd.AddCommand(gendoc.Command(rootCmd, gendoc.Options{})) } func entryPoint(cmd *cobra.Command, _ []string) { diff --git a/cmd/frostfs-lens/root.go b/cmd/frostfs-lens/root.go index ab937add..96ade802 100644 --- a/cmd/frostfs-lens/root.go +++ b/cmd/frostfs-lens/root.go @@ -38,7 +38,7 @@ func init() { blobovnicza.Root, meta.Root, writecache.Root, - gendoc.Command(command), + gendoc.Command(command, gendoc.Options{}), ) } diff --git a/pkg/util/gendoc/gendoc.go b/pkg/util/gendoc/gendoc.go index e7228d0e..14361d8f 100644 --- a/pkg/util/gendoc/gendoc.go +++ b/pkg/util/gendoc/gendoc.go @@ -23,8 +23,25 @@ const ( 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. -func Command(rootCmd *cobra.Command) *cobra.Command { +func Command(rootCmd *cobra.Command, opts Options) *cobra.Command { + opts.fillDefaults() + gendocCmd := &cobra.Command{ Use: "gendoc ", 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: return doc.GenMarkdownTree(rootCmd, args[0]) case gendocMan: - hdr := &doc.GenManHeader{ - Section: "1", - Source: "FrostFS", - } - return doc.GenManTree(rootCmd, hdr, args[0]) + return doc.GenManTree(rootCmd, opts.ManHeader, args[0]) default: return errors.New("type must be 'md' or 'man'") }