[#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 <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-08-08 18:19:11 +03:00 committed by Evgenii Stratonikov
parent 6bcba27757
commit c3e23a1448

View file

@ -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
}