From c3e23a14489b97aab71392e436a435e99f6d7361 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 8 Aug 2023 18:19:11 +0300 Subject: [PATCH] [#578] gendoc: Allow to override flags The command is used in multiple places across the whole FrostFS ecosystem. While we want to have uniform interfaces everywhere, sometimes we can't: already defined global flags can be harder to change because of our obligations to the users. Cobra framework doesn't allow conflicting flags (we can have global ones), so allow to override them. Signed-off-by: Evgenii Stratonikov --- pkg/util/gendoc/gendoc.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/pkg/util/gendoc/gendoc.go b/pkg/util/gendoc/gendoc.go index 5da211e2b..8897bf1e5 100644 --- a/pkg/util/gendoc/gendoc.go +++ b/pkg/util/gendoc/gendoc.go @@ -28,6 +28,18 @@ const ( type Options struct { // Parameters for man generation. By default use (1) section and `FrostFS` source. ManHeader *doc.GenManHeader + // TypeFlag is the flag to use for type, without leading `--`. + // Do not use unless really necessary. + // Default: `type`. + TypeFlag string + // DepthFlag is the flag to use for depth, without leading `--`. + // Do not use unless really necessary. + // Default: `depth`. + DepthFlag string + // ExtensionFlag is the flag to use for extension, without leading `--`. + // Do not use unless really necessary. + // Default: `extension`. + ExtensionFlag string } func (o *Options) fillDefaults() { @@ -39,6 +51,15 @@ func (o *Options) fillDefaults() { Date: &now, } } + if o.TypeFlag == "" { + o.TypeFlag = gendocTypeFlag + } + if o.DepthFlag == "" { + o.DepthFlag = depthFlag + } + if o.ExtensionFlag == "" { + o.ExtensionFlag = extensionFlag + } } // Command returns command which generates user documentation for the argument. @@ -93,9 +114,9 @@ In this case there is a number of helper functions which can be used: } ff := gendocCmd.Flags() - ff.String(gendocTypeFlag, gendocMarkdown, "Type for the documentation ('md' or 'man')") - ff.Int(depthFlag, 1, "If template is specified, unify all commands starting from depth in a single file. Default: 1.") - ff.String(extensionFlag, "", "If the template is specified, string to append to the output file names") + ff.String(opts.TypeFlag, gendocMarkdown, "Type for the documentation ('md' or 'man')") + ff.Int(opts.DepthFlag, 1, "If template is specified, unify all commands starting from depth in a single file. Default: 1.") + ff.String(opts.ExtensionFlag, "", "If the template is specified, string to append to the output file names") return gendocCmd }