mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 03:49:40 -08:00
chore: fix function typo
This commit is contained in:
parent
83149b2298
commit
35c2588365
|
@ -34,26 +34,26 @@ const (
|
||||||
|
|
||||||
// Config holds all the theme for rendering the prompt
|
// Config holds all the theme for rendering the prompt
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
FinalSpace bool `json:"final_space,omitempty"`
|
FinalSpace bool `json:"final_space,omitempty"`
|
||||||
ConsoleTitleTemplate string `json:"console_title_template,omitempty"`
|
ConsoleTitleTemplate string `json:"console_title_template,omitempty"`
|
||||||
TerminalBackground string `json:"terminal_background,omitempty"`
|
TerminalBackground string `json:"terminal_background,omitempty"`
|
||||||
AccentColor string `json:"accent_color,omitempty"`
|
AccentColor string `json:"accent_color,omitempty"`
|
||||||
Blocks []*Block `json:"blocks,omitempty"`
|
Blocks []*Block `json:"blocks,omitempty"`
|
||||||
Tooltips []*Segment `json:"tooltips,omitempty"`
|
Tooltips []*Segment `json:"tooltips,omitempty"`
|
||||||
TransientPrompt *Segment `json:"transient_prompt,omitempty"`
|
TransientPrompt *Segment `json:"transient_prompt,omitempty"`
|
||||||
ValidLine *Segment `json:"valid_line,omitempty"`
|
ValidLine *Segment `json:"valid_line,omitempty"`
|
||||||
ErrorLine *Segment `json:"error_line,omitempty"`
|
ErrorLine *Segment `json:"error_line,omitempty"`
|
||||||
SecondaryPrompt *Segment `json:"secondary_prompt,omitempty"`
|
SecondaryPrompt *Segment `json:"secondary_prompt,omitempty"`
|
||||||
DebugPrompt *Segment `json:"debug_prompt,omitempty"`
|
DebugPrompt *Segment `json:"debug_prompt,omitempty"`
|
||||||
Palette ansi.Palette `json:"palette,omitempty"`
|
Palette ansi.Palette `json:"palette,omitempty"`
|
||||||
Palettes *ansi.Palettes `json:"palettes,omitempty"`
|
Palettes *ansi.Palettes `json:"palettes,omitempty"`
|
||||||
Cycle ansi.Cycle `json:"cycle,omitempty"`
|
Cycle ansi.Cycle `json:"cycle,omitempty"`
|
||||||
ShellIntegration bool `json:"shell_integration,omitempty"`
|
ShellIntegration bool `json:"shell_integration,omitempty"`
|
||||||
PWD string `json:"pwd,omitempty"`
|
PWD string `json:"pwd,omitempty"`
|
||||||
Var map[string]interface{} `json:"var,omitempty"`
|
Var map[string]any `json:"var,omitempty"`
|
||||||
DisableCursorPositioning bool `json:"disable_cursor_positioning,omitempty"`
|
DisableCursorPositioning bool `json:"disable_cursor_positioning,omitempty"`
|
||||||
PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty"`
|
PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty"`
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
OSC99 bool `json:"osc99,omitempty"`
|
OSC99 bool `json:"osc99,omitempty"`
|
||||||
|
@ -174,7 +174,7 @@ func (cfg *Config) sync() {
|
||||||
if !cfg.updated {
|
if !cfg.updated {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var structMap map[string]interface{}
|
var structMap map[string]any
|
||||||
inrec, err := json2.Marshal(cfg)
|
inrec, err := json2.Marshal(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -185,7 +185,7 @@ func (cfg *Config) sync() {
|
||||||
}
|
}
|
||||||
// remove empty structs
|
// remove empty structs
|
||||||
for k, v := range structMap {
|
for k, v := range structMap {
|
||||||
if smap, OK := v.(map[string]interface{}); OK && len(smap) == 0 {
|
if smap, OK := v.(map[string]any); OK && len(smap) == 0 {
|
||||||
delete(structMap, k)
|
delete(structMap, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ func (segment *Segment) hasProperty(property properties.Property) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (segment *Segment) migratePropertyValue(property properties.Property, value interface{}) {
|
func (segment *Segment) migratePropertyValue(property properties.Property, value any) {
|
||||||
if !segment.hasProperty(property) {
|
if !segment.hasProperty(property) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func TestHasProperty(t *testing.T) {
|
||||||
func TestMigratePropertyValue(t *testing.T) {
|
func TestMigratePropertyValue(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
Expected interface{}
|
Expected any
|
||||||
Property properties.Property
|
Property properties.Property
|
||||||
Props properties.Map
|
Props properties.Map
|
||||||
}{
|
}{
|
||||||
|
@ -60,7 +60,7 @@ func TestMigratePropertyValue(t *testing.T) {
|
||||||
func TestMigratePropertyKey(t *testing.T) {
|
func TestMigratePropertyKey(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
Expected interface{}
|
Expected any
|
||||||
OldProperty properties.Property
|
OldProperty properties.Property
|
||||||
NewProperty properties.Property
|
NewProperty properties.Property
|
||||||
Props properties.Map
|
Props properties.Map
|
||||||
|
|
|
@ -65,7 +65,7 @@ type SegmentWriter interface {
|
||||||
// SegmentStyle the style of segment, for more information, see the constants
|
// SegmentStyle the style of segment, for more information, see the constants
|
||||||
type SegmentStyle string
|
type SegmentStyle string
|
||||||
|
|
||||||
func (s *SegmentStyle) Resolve(env platform.Environment, context interface{}) SegmentStyle {
|
func (s *SegmentStyle) Resolve(env platform.Environment, context any) SegmentStyle {
|
||||||
txtTemplate := &template.Text{
|
txtTemplate := &template.Text{
|
||||||
Context: context,
|
Context: context,
|
||||||
Env: env,
|
Env: env,
|
||||||
|
|
|
@ -143,7 +143,7 @@ func TestOauthResult(t *testing.T) {
|
||||||
url := "https://www.strava.com/api/v3/athlete/activities?page=1&per_page=1"
|
url := "https://www.strava.com/api/v3/athlete/activities?page=1&per_page=1"
|
||||||
tokenURL := fmt.Sprintf("https://ohmyposh.dev/api/refresh?segment=test&token=%s", tc.RefreshToken)
|
tokenURL := fmt.Sprintf("https://ohmyposh.dev/api/refresh?segment=test&token=%s", tc.RefreshToken)
|
||||||
|
|
||||||
var props properties.Map = map[properties.Property]interface{}{
|
var props properties.Map = map[properties.Property]any{
|
||||||
properties.CacheTimeout: tc.CacheTimeout,
|
properties.CacheTimeout: tc.CacheTimeout,
|
||||||
properties.AccessToken: tc.AccessToken,
|
properties.AccessToken: tc.AccessToken,
|
||||||
properties.RefreshToken: tc.RefreshToken,
|
properties.RefreshToken: tc.RefreshToken,
|
||||||
|
|
|
@ -62,7 +62,7 @@ func TestRequestResult(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
var props properties.Map = map[properties.Property]interface{}{
|
var props properties.Map = map[properties.Property]any{
|
||||||
properties.CacheTimeout: tc.CacheTimeout,
|
properties.CacheTimeout: tc.CacheTimeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,8 @@ func Get() (*Info, error) {
|
||||||
apm_status, err := cmd.Run("apm", "-b")
|
apm_status, err := cmd.Run("apm", "-b")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseBatteryOutput(apm_percentage, apm_status)
|
return parseBatteryOutput(apm_percentage, apm_status)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,45 +8,45 @@ import (
|
||||||
|
|
||||||
func TestParseBatteryOutput(t *testing.T) {
|
func TestParseBatteryOutput(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
PercentOutput string
|
PercentOutput string
|
||||||
StatusOutput string
|
StatusOutput string
|
||||||
ExpectedState State
|
ExpectedState State
|
||||||
ExpectedPercentage int
|
ExpectedPercentage int
|
||||||
ExpectError bool
|
ExpectError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Case: "charging",
|
Case: "charging",
|
||||||
PercentOutput: "99",
|
PercentOutput: "99",
|
||||||
StatusOutput: "3",
|
StatusOutput: "3",
|
||||||
ExpectedState: Charging,
|
ExpectedState: Charging,
|
||||||
ExpectedPercentage: 99,
|
ExpectedPercentage: 99,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Case: "charging 1%",
|
Case: "charging 1%",
|
||||||
PercentOutput: "1",
|
PercentOutput: "1",
|
||||||
StatusOutput: "3",
|
StatusOutput: "3",
|
||||||
ExpectedState: Charging,
|
ExpectedState: Charging,
|
||||||
ExpectedPercentage: 1,
|
ExpectedPercentage: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Case: "removed",
|
Case: "removed",
|
||||||
PercentOutput: "0",
|
PercentOutput: "0",
|
||||||
StatusOutput: "4",
|
StatusOutput: "4",
|
||||||
ExpectedState: Unknown,
|
ExpectedState: Unknown,
|
||||||
ExpectedPercentage: 0,
|
ExpectedPercentage: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Case: "charged",
|
Case: "charged",
|
||||||
PercentOutput: "100",
|
PercentOutput: "100",
|
||||||
StatusOutput: "0",
|
StatusOutput: "0",
|
||||||
ExpectedState: Full,
|
ExpectedState: Full,
|
||||||
ExpectedPercentage: 100,
|
ExpectedPercentage: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Case: "discharging",
|
Case: "discharging",
|
||||||
PercentOutput: "25",
|
PercentOutput: "25",
|
||||||
StatusOutput: "1",
|
StatusOutput: "1",
|
||||||
ExpectedState: Discharging,
|
ExpectedState: Discharging,
|
||||||
ExpectedPercentage: 25,
|
ExpectedPercentage: 25,
|
||||||
},
|
},
|
||||||
|
|
|
@ -190,7 +190,7 @@ type TemplateCache struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TemplateCache) AddSegmentData(key string, value interface{}) {
|
func (t *TemplateCache) AddSegmentData(key string, value any) {
|
||||||
t.Segments.Set(key, value)
|
t.Segments.Set(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -802,7 +802,7 @@ func (env *Shell) TemplateCache() *TemplateCache {
|
||||||
tmplCache.Segments = NewConcurrentMap()
|
tmplCache.Segments = NewConcurrentMap()
|
||||||
tmplCache.PromptCount = env.CmdFlags.PromptCount
|
tmplCache.PromptCount = env.CmdFlags.PromptCount
|
||||||
tmplCache.Env = make(map[string]string)
|
tmplCache.Env = make(map[string]string)
|
||||||
tmplCache.Var = make(map[string]interface{})
|
tmplCache.Var = make(map[string]any)
|
||||||
|
|
||||||
if env.Var != nil {
|
if env.Var != nil {
|
||||||
tmplCache.Var = env.Var
|
tmplCache.Var = env.Var
|
||||||
|
|
|
@ -54,7 +54,7 @@ const (
|
||||||
CacheTimeout Property = "cache_timeout"
|
CacheTimeout Property = "cache_timeout"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Map map[Property]interface{}
|
type Map map[Property]any
|
||||||
|
|
||||||
func (m Map) GetString(property Property, defaultValue string) string {
|
func (m Map) GetString(property Property, defaultValue string) string {
|
||||||
val, found := m[property]
|
val, found := m[property]
|
||||||
|
@ -158,11 +158,11 @@ func (m Map) GetStringArray(property Property, defaultValue []string) []string {
|
||||||
return keyValues
|
return keyValues
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseStringArray(param interface{}) []string {
|
func ParseStringArray(param any) []string {
|
||||||
switch v := param.(type) {
|
switch v := param.(type) {
|
||||||
default:
|
default:
|
||||||
return []string{}
|
return []string{}
|
||||||
case []interface{}:
|
case []any:
|
||||||
list := make([]string, len(v))
|
list := make([]string, len(v))
|
||||||
for i, v := range v {
|
for i, v := range v {
|
||||||
list[i] = fmt.Sprint(v)
|
list[i] = fmt.Sprint(v)
|
||||||
|
@ -173,11 +173,11 @@ func ParseStringArray(param interface{}) []string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseKeyValueArray(param interface{}) map[string]string {
|
func parseKeyValueArray(param any) map[string]string {
|
||||||
switch v := param.(type) {
|
switch v := param.(type) {
|
||||||
default:
|
default:
|
||||||
return map[string]string{}
|
return map[string]string{}
|
||||||
case map[interface{}]interface{}:
|
case map[any]any:
|
||||||
keyValueArray := make(map[string]string)
|
keyValueArray := make(map[string]string)
|
||||||
for key, value := range v {
|
for key, value := range v {
|
||||||
val := value.(string)
|
val := value.(string)
|
||||||
|
@ -185,14 +185,14 @@ func parseKeyValueArray(param interface{}) map[string]string {
|
||||||
keyValueArray[keyString] = val
|
keyValueArray[keyString] = val
|
||||||
}
|
}
|
||||||
return keyValueArray
|
return keyValueArray
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
keyValueArray := make(map[string]string)
|
keyValueArray := make(map[string]string)
|
||||||
for key, value := range v {
|
for key, value := range v {
|
||||||
val := value.(string)
|
val := value.(string)
|
||||||
keyValueArray[key] = val
|
keyValueArray[key] = val
|
||||||
}
|
}
|
||||||
return keyValueArray
|
return keyValueArray
|
||||||
case []interface{}:
|
case []any:
|
||||||
keyValueArray := make(map[string]string)
|
keyValueArray := make(map[string]string)
|
||||||
for _, s := range v {
|
for _, s := range v {
|
||||||
l := ParseStringArray(s)
|
l := ParseStringArray(s)
|
||||||
|
|
|
@ -89,7 +89,7 @@ func TestGetFloat64(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
Expected float64
|
Expected float64
|
||||||
Input interface{}
|
Input any
|
||||||
}{
|
}{
|
||||||
{Case: "int", Expected: 1337, Input: 1337},
|
{Case: "int", Expected: 1337, Input: 1337},
|
||||||
{Case: "float64", Expected: 1337, Input: float64(1337)},
|
{Case: "float64", Expected: 1337, Input: float64(1337)},
|
||||||
|
|
|
@ -33,15 +33,15 @@ type AzureConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AzureSubscription struct {
|
type AzureSubscription struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
User *AzureUser `json:"user"`
|
User *AzureUser `json:"user"`
|
||||||
IsDefault bool `json:"isDefault"`
|
IsDefault bool `json:"isDefault"`
|
||||||
TenantID string `json:"tenantId"`
|
TenantID string `json:"tenantId"`
|
||||||
EnvironmentName string `json:"environmentName"`
|
EnvironmentName string `json:"environmentName"`
|
||||||
HomeTenantID string `json:"homeTenantId"`
|
HomeTenantID string `json:"homeTenantId"`
|
||||||
ManagedByTenants []interface{} `json:"managedByTenants"`
|
ManagedByTenants []any `json:"managedByTenants"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AzureUser struct {
|
type AzureUser struct {
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
mock2 "github.com/stretchr/testify/mock"
|
mock2 "github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate string, context interface{}) string {
|
func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate string, context any) string {
|
||||||
found := false
|
found := false
|
||||||
for _, call := range env.Mock.ExpectedCalls {
|
for _, call := range env.Mock.ExpectedCalls {
|
||||||
if call.Method == "TemplateCache" {
|
if call.Method == "TemplateCache" {
|
||||||
|
@ -42,7 +42,7 @@ func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate stri
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context interface{}) string {
|
func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context any) string {
|
||||||
return strings.TrimSpace(renderTemplateNoTrimSpace(env, segmentTemplate, context))
|
return strings.TrimSpace(renderTemplateNoTrimSpace(env, segmentTemplate, context))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ func TestTruncateBranch(t *testing.T) {
|
||||||
Expected string
|
Expected string
|
||||||
Branch string
|
Branch string
|
||||||
FullBranch bool
|
FullBranch bool
|
||||||
MaxLength interface{}
|
MaxLength any
|
||||||
}{
|
}{
|
||||||
{Case: "No limit", Expected: "are-belong-to-us", Branch: "/all-your-base/are-belong-to-us", FullBranch: false},
|
{Case: "No limit", Expected: "are-belong-to-us", Branch: "/all-your-base/are-belong-to-us", FullBranch: false},
|
||||||
{Case: "No limit - larger", Expected: "are-belong", Branch: "/all-your-base/are-belong-to-us", FullBranch: false, MaxLength: 10.0},
|
{Case: "No limit - larger", Expected: "are-belong", Branch: "/all-your-base/are-belong-to-us", FullBranch: false, MaxLength: 10.0},
|
||||||
|
@ -146,8 +146,8 @@ func TestTruncateBranchWithSymbol(t *testing.T) {
|
||||||
Expected string
|
Expected string
|
||||||
Branch string
|
Branch string
|
||||||
FullBranch bool
|
FullBranch bool
|
||||||
MaxLength interface{}
|
MaxLength any
|
||||||
TruncateSymbol interface{}
|
TruncateSymbol any
|
||||||
}{
|
}{
|
||||||
{Case: "No limit", Expected: "are-belong-to-us", Branch: "/all-your-base/are-belong-to-us", FullBranch: false, TruncateSymbol: "..."},
|
{Case: "No limit", Expected: "are-belong-to-us", Branch: "/all-your-base/are-belong-to-us", FullBranch: false, TruncateSymbol: "..."},
|
||||||
{Case: "No limit - larger", Expected: "are-belong...", Branch: "/all-your-base/are-belong-to-us", FullBranch: false, MaxLength: 10.0, TruncateSymbol: "..."},
|
{Case: "No limit - larger", Expected: "are-belong...", Branch: "/all-your-base/are-belong-to-us", FullBranch: false, MaxLength: 10.0, TruncateSymbol: "..."},
|
||||||
|
|
|
@ -29,8 +29,8 @@ type Body struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MeasureGroup struct {
|
type MeasureGroup struct {
|
||||||
Measures []*Measure `json:"measures"`
|
Measures []*Measure `json:"measures"`
|
||||||
Comment interface{} `json:"comment"`
|
Comment any `json:"comment"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Measure struct {
|
type Measure struct {
|
||||||
|
|
|
@ -1,19 +1,36 @@
|
||||||
package template
|
package template
|
||||||
|
|
||||||
func interFaceToInt(e interface{}) int {
|
import (
|
||||||
if val, OK := e.(int); OK {
|
"errors"
|
||||||
return val
|
"strconv"
|
||||||
}
|
)
|
||||||
if val, OK := e.(float64); OK {
|
|
||||||
return int(val)
|
func toIntOrZero(e any) int {
|
||||||
}
|
if value, err := toInt(e); err == nil {
|
||||||
if val, OK := e.(int64); OK {
|
return value
|
||||||
return int(val)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func interfaceToFloat64(e interface{}) float64 {
|
func toInt(integer any) (int, error) {
|
||||||
|
switch seconds := integer.(type) {
|
||||||
|
default:
|
||||||
|
return 0, errors.New("invalid integer type")
|
||||||
|
case string:
|
||||||
|
return strconv.Atoi(seconds)
|
||||||
|
case int:
|
||||||
|
return seconds, nil
|
||||||
|
case int64:
|
||||||
|
return int(seconds), nil
|
||||||
|
case uint64:
|
||||||
|
return int(seconds), nil
|
||||||
|
case float64:
|
||||||
|
return int(seconds), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func toFloat64(e any) float64 {
|
||||||
if val, OK := e.(float64); OK {
|
if val, OK := e.(float64); OK {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
@ -26,19 +43,19 @@ func interfaceToFloat64(e interface{}) float64 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func gt(e1, e2 interface{}) bool {
|
func gt(e1, e2 any) bool {
|
||||||
if val, OK := e1.(int); OK {
|
if val, OK := e1.(int); OK {
|
||||||
return val > interFaceToInt(e2)
|
return val > toIntOrZero(e2)
|
||||||
}
|
}
|
||||||
if val, OK := e1.(int64); OK {
|
if val, OK := e1.(int64); OK {
|
||||||
return val > int64(interFaceToInt(e2))
|
return val > int64(toIntOrZero(e2))
|
||||||
}
|
}
|
||||||
if val, OK := e1.(float64); OK {
|
if val, OK := e1.(float64); OK {
|
||||||
return val > interfaceToFloat64(e2)
|
return val > toFloat64(e2)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func lt(e1, e2 interface{}) bool {
|
func lt(e1, e2 any) bool {
|
||||||
return gt(e2, e1)
|
return gt(e2, e1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ func TestGt(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
Expected bool
|
Expected bool
|
||||||
E1 interface{}
|
E1 any
|
||||||
E2 interface{}
|
E2 any
|
||||||
}{
|
}{
|
||||||
{Case: "Float vs int", Expected: false, E1: float64(3), E2: 4},
|
{Case: "Float vs int", Expected: false, E1: float64(3), E2: 4},
|
||||||
{Case: "Int vs float", Expected: false, E1: 3, E2: float64(4)},
|
{Case: "Int vs float", Expected: false, E1: 3, E2: float64(4)},
|
||||||
|
@ -33,8 +33,8 @@ func TestLt(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
Expected bool
|
Expected bool
|
||||||
E1 interface{}
|
E1 any
|
||||||
E2 interface{}
|
E2 any
|
||||||
}{
|
}{
|
||||||
{Case: "Float vs int", Expected: true, E1: float64(3), E2: 4},
|
{Case: "Float vs int", Expected: true, E1: float64(3), E2: 4},
|
||||||
{Case: "Int vs float", Expected: true, E1: 3, E2: float64(4)},
|
{Case: "Int vs float", Expected: true, E1: 3, E2: float64(4)},
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func funcMap() template.FuncMap {
|
func funcMap() template.FuncMap {
|
||||||
funcMap := map[string]interface{}{
|
funcMap := map[string]any{
|
||||||
"secondsRound": secondsRound,
|
"secondsRound": secondsRound,
|
||||||
"url": url,
|
"url": url,
|
||||||
"path": path,
|
"path": path,
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (l List) Empty() bool {
|
||||||
return len(l) == 0
|
return len(l) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l List) Resolve(context interface{}, env platform.Environment, defaultValue string, logic Logic) string {
|
func (l List) Resolve(context any, env platform.Environment, defaultValue string, logic Logic) string {
|
||||||
switch logic {
|
switch logic {
|
||||||
case FirstMatch:
|
case FirstMatch:
|
||||||
return l.FirstMatch(context, env, defaultValue)
|
return l.FirstMatch(context, env, defaultValue)
|
||||||
|
@ -30,7 +30,7 @@ func (l List) Resolve(context interface{}, env platform.Environment, defaultValu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l List) Join(context interface{}, env platform.Environment) string {
|
func (l List) Join(context any, env platform.Environment) string {
|
||||||
if len(l) == 0 {
|
if len(l) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func (l List) Join(context interface{}, env platform.Environment) string {
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l List) FirstMatch(context interface{}, env platform.Environment, defaultValue string) string {
|
func (l List) FirstMatch(context any, env platform.Environment, defaultValue string) string {
|
||||||
if len(l) == 0 {
|
if len(l) == 0 {
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,10 @@
|
||||||
package template
|
package template
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func toInt(integer any) (int, error) {
|
|
||||||
switch seconds := integer.(type) {
|
|
||||||
default:
|
|
||||||
return 0, errors.New("invalid integer type")
|
|
||||||
case string:
|
|
||||||
return strconv.Atoi(seconds)
|
|
||||||
case int:
|
|
||||||
return seconds, nil
|
|
||||||
case int64:
|
|
||||||
return int(seconds), nil
|
|
||||||
case uint64:
|
|
||||||
return int(seconds), nil
|
|
||||||
case float64:
|
|
||||||
return int(seconds), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func secondsRound(seconds any) string {
|
func secondsRound(seconds any) string {
|
||||||
s, err := toInt(seconds)
|
s, err := toInt(seconds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -42,12 +42,12 @@ var (
|
||||||
|
|
||||||
type Text struct {
|
type Text struct {
|
||||||
Template string
|
Template string
|
||||||
Context interface{}
|
Context any
|
||||||
Env platform.Environment
|
Env platform.Environment
|
||||||
TemplatesResult string
|
TemplatesResult string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Data interface{}
|
type Data any
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
*platform.TemplateCache
|
*platform.TemplateCache
|
||||||
|
@ -91,7 +91,7 @@ func (t *Text) Render() (string, error) {
|
||||||
return "", errors.New(msg["MSG"])
|
return "", errors.New(msg["MSG"])
|
||||||
}
|
}
|
||||||
text := buffer.String()
|
text := buffer.String()
|
||||||
// issue with missingkey=zero ignored for map[string]interface{}
|
// issue with missingkey=zero ignored for map[string]any
|
||||||
// https://github.com/golang/go/issues/24963
|
// https://github.com/golang/go/issues/24963
|
||||||
text = strings.ReplaceAll(text, "<no value>", "")
|
text = strings.ReplaceAll(text, "<no value>", "")
|
||||||
return text, nil
|
return text, nil
|
||||||
|
@ -195,7 +195,7 @@ func (t *Text) cleanTemplate() {
|
||||||
|
|
||||||
type fields map[string]bool
|
type fields map[string]bool
|
||||||
|
|
||||||
func (f *fields) init(data interface{}) {
|
func (f *fields) init(data any) {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ func (f *fields) init(data interface{}) {
|
||||||
(*f)[val.Field(i).Name] = true
|
(*f)[val.Field(i).Name] = true
|
||||||
}
|
}
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
m, ok := data.(map[string]interface{})
|
m, ok := data.(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestRenderTemplate(t *testing.T) {
|
||||||
Expected string
|
Expected string
|
||||||
Template string
|
Template string
|
||||||
ShouldError bool
|
ShouldError bool
|
||||||
Context interface{}
|
Context any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Case: "dot literal",
|
Case: "dot literal",
|
||||||
|
@ -184,7 +184,7 @@ func TestRenderTemplateEnvVar(t *testing.T) {
|
||||||
Template string
|
Template string
|
||||||
ShouldError bool
|
ShouldError bool
|
||||||
Env map[string]string
|
Env map[string]string
|
||||||
Context interface{}
|
Context any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Case: "nil struct with env var",
|
Case: "nil struct with env var",
|
||||||
|
@ -197,7 +197,7 @@ func TestRenderTemplateEnvVar(t *testing.T) {
|
||||||
Case: "map with env var",
|
Case: "map with env var",
|
||||||
Expected: "hello world",
|
Expected: "hello world",
|
||||||
Template: "{{.Env.HELLO}} {{.World}}",
|
Template: "{{.Env.HELLO}} {{.World}}",
|
||||||
Context: map[string]interface{}{"World": "world"},
|
Context: map[string]any{"World": "world"},
|
||||||
Env: map[string]string{"HELLO": "hello"},
|
Env: map[string]string{"HELLO": "hello"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -208,7 +208,7 @@ func TestRenderTemplateEnvVar(t *testing.T) {
|
||||||
Env: map[string]string{"HELLO": "hello"},
|
Env: map[string]string{"HELLO": "hello"},
|
||||||
},
|
},
|
||||||
{Case: "no env var", Expected: "hello world", Template: "{{.Text}} world", Context: struct{ Text string }{Text: "hello"}},
|
{Case: "no env var", Expected: "hello world", Template: "{{.Text}} world", Context: struct{ Text string }{Text: "hello"}},
|
||||||
{Case: "map", Expected: "hello world", Template: "{{.Text}} world", Context: map[string]interface{}{"Text": "hello"}},
|
{Case: "map", Expected: "hello world", Template: "{{.Text}} world", Context: map[string]any{"Text": "hello"}},
|
||||||
{Case: "empty map", Expected: " world", Template: "{{.Text}} world", Context: map[string]string{}},
|
{Case: "empty map", Expected: " world", Template: "{{.Text}} world", Context: map[string]string{}},
|
||||||
{
|
{
|
||||||
Case: "Struct with duplicate property",
|
Case: "Struct with duplicate property",
|
||||||
|
@ -228,14 +228,14 @@ func TestRenderTemplateEnvVar(t *testing.T) {
|
||||||
Case: "Map with duplicate property",
|
Case: "Map with duplicate property",
|
||||||
Expected: "posh",
|
Expected: "posh",
|
||||||
Template: "{{ .OS }}",
|
Template: "{{ .OS }}",
|
||||||
Context: map[string]interface{}{"OS": "posh"},
|
Context: map[string]any{"OS": "posh"},
|
||||||
Env: map[string]string{"HELLO": "hello"},
|
Env: map[string]string{"HELLO": "hello"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Case: "Non-supported map",
|
Case: "Non-supported map",
|
||||||
Expected: "darwin",
|
Expected: "darwin",
|
||||||
Template: "{{ .OS }}",
|
Template: "{{ .OS }}",
|
||||||
Context: map[int]interface{}{},
|
Context: map[int]any{},
|
||||||
Env: map[string]string{"HELLO": "hello"},
|
Env: map[string]string{"HELLO": "hello"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ func TestCleanTemplate(t *testing.T) {
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
tmpl := &Text{
|
tmpl := &Text{
|
||||||
Template: tc.Template,
|
Template: tc.Template,
|
||||||
Context: map[string]interface{}{"OS": "posh"},
|
Context: map[string]any{"OS": "posh"},
|
||||||
}
|
}
|
||||||
tmpl.cleanTemplate()
|
tmpl.cleanTemplate()
|
||||||
assert.Equal(t, tc.Expected, tmpl.Template, tc.Case)
|
assert.Equal(t, tc.Expected, tmpl.Template, tc.Case)
|
||||||
|
|
Loading…
Reference in a new issue