[#578] gendoc: Allow to override flags
Some checks failed
Build / Build Components (1.19) (pull_request) Failing after 3s
Tests and linters / Lint (pull_request) Failing after 4s
Tests and linters / Tests (1.20) (pull_request) Failing after 3s
Tests and linters / Tests with -race (pull_request) Failing after 2s
Tests and linters / Staticcheck (pull_request) Failing after 3s
Vulncheck / Vulncheck (pull_request) Failing after 3s
Build / Build Components (1.20) (pull_request) Successful in 9m37s
Tests and linters / Tests (1.19) (pull_request) Successful in 11m6s
Some checks failed
Build / Build Components (1.19) (pull_request) Failing after 3s
Tests and linters / Lint (pull_request) Failing after 4s
Tests and linters / Tests (1.20) (pull_request) Failing after 3s
Tests and linters / Tests with -race (pull_request) Failing after 2s
Tests and linters / Staticcheck (pull_request) Failing after 3s
Vulncheck / Vulncheck (pull_request) Failing after 3s
Build / Build Components (1.20) (pull_request) Successful in 9m37s
Tests and linters / Tests (1.19) (pull_request) Successful in 11m6s
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
920c6117b6
commit
8e24665d96
1 changed files with 24 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue