mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
103 lines
2.2 KiB
Go
103 lines
2.2 KiB
Go
package docvalues
|
|
|
|
import (
|
|
"config-lsp/common"
|
|
"config-lsp/utils"
|
|
"regexp"
|
|
)
|
|
|
|
// UserValue returns a DeprecatedValue that fetches user names from /etc/passwd
|
|
// if `separatorForMultiple` is not empty, it will return an ArrayValue
|
|
func UserValue(separatorForMultiple string, enforceValues bool) DeprecatedValue {
|
|
return CustomValue{
|
|
FetchValue: func(context CustomValueContext) DeprecatedValue {
|
|
infos, err := common.FetchPasswdInfo()
|
|
|
|
if err != nil {
|
|
return StringValue{}
|
|
}
|
|
|
|
enumValues := EnumValue{
|
|
EnforceValues: enforceValues,
|
|
Values: utils.Map(infos, func(info common.PasswdInfo) EnumString {
|
|
return CreateEnumString(info.Name)
|
|
}),
|
|
}
|
|
|
|
if separatorForMultiple == "" {
|
|
return enumValues
|
|
} else {
|
|
return ArrayValue{
|
|
DuplicatesExtractor: &SimpleDuplicatesExtractor,
|
|
SubValue: enumValues,
|
|
Separator: separatorForMultiple,
|
|
}
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|
|
func GroupValue(separatorForMultiple string, enforceValues bool) DeprecatedValue {
|
|
return CustomValue{
|
|
FetchValue: func(context CustomValueContext) DeprecatedValue {
|
|
infos, err := common.FetchGroupInfo()
|
|
|
|
if err != nil {
|
|
return StringValue{}
|
|
}
|
|
|
|
enumValues := EnumValue{
|
|
EnforceValues: enforceValues,
|
|
Values: utils.Map(infos, func(info common.GroupInfo) EnumString {
|
|
return CreateEnumString(info.Name)
|
|
}),
|
|
}
|
|
|
|
if separatorForMultiple == "" {
|
|
return enumValues
|
|
} else {
|
|
return ArrayValue{
|
|
DuplicatesExtractor: &SimpleDuplicatesExtractor,
|
|
SubValue: enumValues,
|
|
Separator: separatorForMultiple,
|
|
}
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|
|
func NumberRangeValue(min int, max int) DeprecatedValue {
|
|
return NumberValue{
|
|
Min: &min,
|
|
Max: &max,
|
|
}
|
|
}
|
|
|
|
func PositiveNumberValue() DeprecatedValue {
|
|
zero := 0
|
|
return NumberValue{
|
|
Min: &zero,
|
|
}
|
|
}
|
|
|
|
func MaskValue() DeprecatedValue {
|
|
min := 0
|
|
max := 777
|
|
return NumberValue{Min: &min, Max: &max}
|
|
}
|
|
|
|
func SingleEnumValue(value string) EnumValue {
|
|
return EnumValue{
|
|
EnforceValues: true,
|
|
Values: []EnumString{
|
|
CreateEnumString(value),
|
|
},
|
|
}
|
|
}
|
|
|
|
func DomainValue() DeprecatedValue {
|
|
return RegexValue{
|
|
Regex: *regexp.MustCompile(`^.+?\..+$`),
|
|
}
|
|
}
|