2022-04-22 17:38:40 +02:00
|
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"reflect"
|
2022-07-05 23:13:34 +02:00
|
|
|
|
"strings"
|
2022-04-22 17:38:40 +02:00
|
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/list"
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// CliFlag represents a command-line parameter.
|
|
|
|
|
type CliFlag struct {
|
|
|
|
|
Flag cli.DocGenerationFlag
|
|
|
|
|
Tags []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Skip checks if the parameter should be skipped based on a list of tags.
|
|
|
|
|
func (f CliFlag) Skip(tags []string) bool {
|
|
|
|
|
return len(f.Tags) > 0 && !list.ContainsAny(f.Tags, tags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fields returns the flag struct fields.
|
|
|
|
|
func (f CliFlag) Fields() reflect.Value {
|
|
|
|
|
fields := reflect.ValueOf(f.Flag)
|
|
|
|
|
|
|
|
|
|
for fields.Kind() == reflect.Ptr {
|
|
|
|
|
fields = reflect.Indirect(fields)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fields
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 23:13:34 +02:00
|
|
|
|
// Default returns the default value.
|
|
|
|
|
func (f CliFlag) Default() string {
|
|
|
|
|
return f.Flag.GetValue()
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:38:40 +02:00
|
|
|
|
// Hidden checks if the flag is hidden.
|
|
|
|
|
func (f CliFlag) Hidden() bool {
|
|
|
|
|
field := f.Fields().FieldByName("Hidden")
|
|
|
|
|
|
|
|
|
|
if !field.IsValid() || !field.Bool() {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EnvVar returns the flag environment variable name.
|
|
|
|
|
func (f CliFlag) EnvVar() string {
|
|
|
|
|
field := f.Fields().FieldByName("EnvVar")
|
|
|
|
|
|
|
|
|
|
if !field.IsValid() {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return field.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Name returns the command flag name.
|
|
|
|
|
func (f CliFlag) Name() string {
|
|
|
|
|
return f.Flag.GetName()
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 23:13:34 +02:00
|
|
|
|
// CommandFlag returns the full command flag based on the name.
|
|
|
|
|
func (f CliFlag) CommandFlag() string {
|
|
|
|
|
n := strings.Split(f.Name(), ",")
|
|
|
|
|
return "--" + n[0]
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:38:40 +02:00
|
|
|
|
// Usage returns the command flag usage.
|
|
|
|
|
func (f CliFlag) Usage() string {
|
|
|
|
|
if list.Contains(f.Tags, EnvSponsor) {
|
2023-04-29 13:52:42 +02:00
|
|
|
|
return f.Flag.GetUsage() + " *members only*"
|
2023-06-01 16:35:07 +02:00
|
|
|
|
} else if list.Contains(f.Tags, Pro) {
|
|
|
|
|
return f.Flag.GetUsage() + " *pro*"
|
2023-05-01 18:32:37 +02:00
|
|
|
|
} else if list.Contains(f.Tags, Plus) {
|
|
|
|
|
return f.Flag.GetUsage() + " *plus*"
|
2023-06-01 16:35:07 +02:00
|
|
|
|
} else if list.Contains(f.Tags, Essentials) {
|
|
|
|
|
return f.Flag.GetUsage() + " *essentials*"
|
2022-04-22 17:38:40 +02:00
|
|
|
|
} else {
|
|
|
|
|
return f.Flag.GetUsage()
|
|
|
|
|
}
|
|
|
|
|
}
|