|
|
|
@ -126,6 +126,21 @@ type Flag interface {
|
|
|
|
|
RunAction(*Context) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DocGenerationFlag is an interface that allows documentation generation for the flag
|
|
|
|
|
type DocGenerationFlag interface {
|
|
|
|
|
Flag
|
|
|
|
|
|
|
|
|
|
// TakesValue returns true if the flag takes a value, otherwise false
|
|
|
|
|
TakesValue() bool
|
|
|
|
|
|
|
|
|
|
// GetValue returns the flags value as string representation and an empty
|
|
|
|
|
// string if the flag takes no value at all.
|
|
|
|
|
GetValue() string
|
|
|
|
|
|
|
|
|
|
// GetEnvVars returns the env vars for this flag
|
|
|
|
|
GetEnvVars() []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DocGenerationSliceFlag extends DocGenerationFlag for slice-based flags.
|
|
|
|
|
type DocGenerationSliceFlag interface {
|
|
|
|
|
DocGenerationFlag
|
|
|
|
@ -293,8 +308,14 @@ func formatDefault(format string) string {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func stringifyFlag(f Flag) string {
|
|
|
|
|
placeholder, usage := unquoteUsage(f.GetUsage())
|
|
|
|
|
needsPlaceholder := f.TakesValue()
|
|
|
|
|
// enforce DocGeneration interface on flags to avoid reflection
|
|
|
|
|
df, ok := f.(DocGenerationFlag)
|
|
|
|
|
if !ok {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
placeholder, usage := unquoteUsage(df.GetUsage())
|
|
|
|
|
needsPlaceholder := df.TakesValue()
|
|
|
|
|
|
|
|
|
|
if needsPlaceholder && placeholder == "" {
|
|
|
|
|
placeholder = defaultPlaceholder
|
|
|
|
@ -302,7 +323,7 @@ func stringifyFlag(f Flag) string {
|
|
|
|
|
|
|
|
|
|
defaultValueString := ""
|
|
|
|
|
|
|
|
|
|
if s := f.GetDefaultText(); s != "" {
|
|
|
|
|
if s := df.GetDefaultText(); s != "" {
|
|
|
|
|
defaultValueString = fmt.Sprintf(formatDefault("%s"), s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|