forked from TrueCloudLab/frostfs-node
[#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:
parent
6bcba27757
commit
c3e23a1448
1 changed files with 24 additions and 3 deletions
|
@ -28,6 +28,18 @@ const (
|
||||||
type Options struct {
|
type Options struct {
|
||||||
// Parameters for man generation. By default use (1) section and `FrostFS` source.
|
// Parameters for man generation. By default use (1) section and `FrostFS` source.
|
||||||
ManHeader *doc.GenManHeader
|
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() {
|
func (o *Options) fillDefaults() {
|
||||||
|
@ -39,6 +51,15 @@ func (o *Options) fillDefaults() {
|
||||||
Date: &now,
|
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.
|
// 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 := gendocCmd.Flags()
|
||||||
ff.String(gendocTypeFlag, gendocMarkdown, "Type for the documentation ('md' or 'man')")
|
ff.String(opts.TypeFlag, 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.Int(opts.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.ExtensionFlag, "", "If the template is specified, string to append to the output file names")
|
||||||
return gendocCmd
|
return gendocCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue