mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
refactor: public interface for segments
This commit is contained in:
parent
59756813d3
commit
4e17e4a853
|
@ -7,54 +7,45 @@ sidebar_label: Add Segment
|
|||
## Create the logic
|
||||
|
||||
Add a new file following this convention: `new_segment.go`.
|
||||
Ensure `new` is a single verb indicating the context the segment renders.
|
||||
Ensure `New` is a single verb indicating the context the segment renders.
|
||||
|
||||
You can use the following template as a guide.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
type new struct {
|
||||
props Properties
|
||||
env Environment
|
||||
import (
|
||||
"oh-my-posh/environment"
|
||||
"oh-my-posh/properties"
|
||||
)
|
||||
|
||||
type New struct {
|
||||
props properties.Properties
|
||||
env environment.Environment
|
||||
|
||||
Text string
|
||||
}
|
||||
|
||||
const (
|
||||
//NewProp enables something
|
||||
NewProp Property = "newprop"
|
||||
NewProp properties.Property = "newprop"
|
||||
)
|
||||
|
||||
func (n *new) enabled() bool {
|
||||
func (n *new) Enabled() bool {
|
||||
true
|
||||
}
|
||||
|
||||
func (n *new) string() string {
|
||||
useDefaultText := n.props.getBool(NewProp, true)
|
||||
if useDefaultText {
|
||||
n.Text = "Hello"
|
||||
}
|
||||
segmentTemplate := n.props.getString(SegmentTemplate, "{{.Text}} world")
|
||||
template := &textTemplate{
|
||||
Template: segmentTemplate,
|
||||
Context: n,
|
||||
Env: n.env,
|
||||
}
|
||||
text, err := template.render()
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return text
|
||||
func (n *new) Template() string {
|
||||
return "{{.Text}} world"
|
||||
}
|
||||
|
||||
func (n *new) init(props Properties, env Environment) {
|
||||
func (n *new) Init(props properties.Properties, env environment.Environment) {
|
||||
n.props = props
|
||||
n.env = env
|
||||
}
|
||||
```
|
||||
|
||||
When it comes to icon properties, make sure to use the UTF32 representation (e.g. "\uEFF1") rather than the icon itself.
|
||||
When it comes to icon Properties, make sure to use the UTF32 representation (e.g. "\uEFF1") rather than the icon itself.
|
||||
This will facilitate the review process as not all environments display the icons based on the font being used.
|
||||
You can find these values and query for icons easily at [Nerd Fonts][nf-icons].
|
||||
|
||||
|
@ -62,9 +53,6 @@ For each segment, there's a single test file ensuring the functionality going fo
|
|||
is `new_segment_test.go`, have a look at [existing segment tests][tests] for inspiration. Oh My Posh makes
|
||||
use of the test tables pattern for all newly added tests. See [this][tables] blog post for more information.
|
||||
|
||||
The use of a `SegmentTemplate` is required. We're currently in the process of refactoring all segments to use
|
||||
a template. As soon as this work is done, the templating logic will move outside of the segment's logic.
|
||||
|
||||
## Create a name for your Segment
|
||||
|
||||
[`segment.go`][segment-go] contains the list of available `SegmentType`'s, which gives them a name we can map from the
|
||||
|
@ -73,8 +61,8 @@ a template. As soon as this work is done, the templating logic will move outside
|
|||
Add your segment.
|
||||
|
||||
```go
|
||||
//New is brand new
|
||||
New SegmentType = "new"
|
||||
// NEW is brand new
|
||||
NEW SegmentType = "new"
|
||||
```
|
||||
|
||||
## Add the SegmentType mapping
|
||||
|
@ -82,7 +70,7 @@ New SegmentType = "new"
|
|||
Map your `SegmentType` to your Segment in the `mapSegmentWithWriter` function.
|
||||
|
||||
```go
|
||||
New: &new{},
|
||||
NEW: &New{},
|
||||
```
|
||||
|
||||
## Test your functionality
|
||||
|
|
|
@ -50,7 +50,7 @@ const (
|
|||
FullBranchPath properties.Property = "full_branch_path"
|
||||
)
|
||||
|
||||
func (s *scm) init(props properties.Properties, env environment.Environment) {
|
||||
func (s *scm) Init(props properties.Properties, env environment.Environment) {
|
||||
s.props = props
|
||||
s.env = env
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ type SegmentTiming struct {
|
|||
|
||||
// SegmentWriter is the interface used to define what and if to write to the prompt
|
||||
type SegmentWriter interface {
|
||||
enabled() bool
|
||||
template() string
|
||||
init(props properties.Properties, env environment.Environment)
|
||||
Enabled() bool
|
||||
Template() string
|
||||
Init(props properties.Properties, env environment.Environment)
|
||||
}
|
||||
|
||||
// SegmentStyle the syle of segment, for more information, see the constants
|
||||
|
@ -149,7 +149,7 @@ const (
|
|||
|
||||
func (segment *Segment) string() string {
|
||||
template := &textTemplate{
|
||||
Template: segment.writer.template(),
|
||||
Template: segment.writer.Template(),
|
||||
Context: segment.writer,
|
||||
Env: segment.env,
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ func (segment *Segment) string() string {
|
|||
}
|
||||
|
||||
func (segment *Segment) enabled() bool {
|
||||
segment.active = segment.writer.enabled()
|
||||
segment.active = segment.writer.Enabled()
|
||||
return segment.active
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ func (segment *Segment) mapSegmentWithWriter(env environment.Environment) error
|
|||
segment.Properties = make(properties.Map)
|
||||
}
|
||||
if writer, ok := functions[segment.Type]; ok {
|
||||
writer.init(segment.Properties, env)
|
||||
writer.Init(segment.Properties, env)
|
||||
segment.writer = writer
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ type Angular struct {
|
|||
language
|
||||
}
|
||||
|
||||
func (a *Angular) template() string {
|
||||
func (a *Angular) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (a *Angular) init(props properties.Properties, env environment.Environment) {
|
||||
func (a *Angular) Init(props properties.Properties, env environment.Environment) {
|
||||
a.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -50,6 +50,6 @@ func (a *Angular) init(props properties.Properties, env environment.Environment)
|
|||
}
|
||||
}
|
||||
|
||||
func (a *Angular) enabled() bool {
|
||||
return a.language.enabled()
|
||||
func (a *Angular) Enabled() bool {
|
||||
return a.language.Enabled()
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ func TestAngularCliVersionDisplayed(t *testing.T) {
|
|||
})
|
||||
props := properties.Map{}
|
||||
angular := &Angular{}
|
||||
angular.init(props, env)
|
||||
assert.True(t, angular.enabled(), fmt.Sprintf("Failed in case: %s", ta.Case))
|
||||
assert.Equal(t, ta.FullVersion, renderTemplate(env, angular.template(), angular), fmt.Sprintf("Failed in case: %s", ta.Case))
|
||||
angular.Init(props, env)
|
||||
assert.True(t, angular.Enabled(), fmt.Sprintf("Failed in case: %s", ta.Case))
|
||||
assert.Equal(t, ta.FullVersion, renderTemplate(env, angular.Template(), angular), fmt.Sprintf("Failed in case: %s", ta.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,16 +19,16 @@ const (
|
|||
defaultUser = "default"
|
||||
)
|
||||
|
||||
func (a *Aws) template() string {
|
||||
func (a *Aws) Template() string {
|
||||
return "{{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }}"
|
||||
}
|
||||
|
||||
func (a *Aws) init(props properties.Properties, env environment.Environment) {
|
||||
func (a *Aws) Init(props properties.Properties, env environment.Environment) {
|
||||
a.props = props
|
||||
a.env = env
|
||||
}
|
||||
|
||||
func (a *Aws) enabled() bool {
|
||||
func (a *Aws) Enabled() bool {
|
||||
getEnvFirstMatch := func(envs ...string) string {
|
||||
for _, env := range envs {
|
||||
value := a.env.Getenv(env)
|
||||
|
|
|
@ -64,9 +64,9 @@ func TestAWSSegment(t *testing.T) {
|
|||
props: props,
|
||||
}
|
||||
if tc.Template == "" {
|
||||
tc.Template = aws.template()
|
||||
tc.Template = aws.Template()
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedEnabled, aws.enabled(), tc.Case)
|
||||
assert.Equal(t, tc.ExpectedEnabled, aws.Enabled(), tc.Case)
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, aws), tc.Case)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,16 +80,16 @@ type AzurePowerShellSubscription struct {
|
|||
} `json:"Environment"`
|
||||
}
|
||||
|
||||
func (a *Az) template() string {
|
||||
func (a *Az) Template() string {
|
||||
return "{{ .Name }}"
|
||||
}
|
||||
|
||||
func (a *Az) init(props properties.Properties, env environment.Environment) {
|
||||
func (a *Az) Init(props properties.Properties, env environment.Environment) {
|
||||
a.props = props
|
||||
a.env = env
|
||||
}
|
||||
|
||||
func (a *Az) enabled() bool {
|
||||
func (a *Az) Enabled() bool {
|
||||
return a.getAzureProfile() || a.getAzureRmContext()
|
||||
}
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ type AzFunc struct {
|
|||
language
|
||||
}
|
||||
|
||||
func (az *AzFunc) template() string {
|
||||
func (az *AzFunc) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (az *AzFunc) init(props properties.Properties, env environment.Environment) {
|
||||
func (az *AzFunc) Init(props properties.Properties, env environment.Environment) {
|
||||
az.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -28,6 +28,6 @@ func (az *AzFunc) init(props properties.Properties, env environment.Environment)
|
|||
}
|
||||
}
|
||||
|
||||
func (az *AzFunc) enabled() bool {
|
||||
return az.language.enabled()
|
||||
func (az *AzFunc) Enabled() bool {
|
||||
return az.language.Enabled()
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ func TestAzSegment(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedEnabled, az.enabled(), tc.Case)
|
||||
assert.Equal(t, tc.ExpectedEnabled, az.Enabled(), tc.Case)
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, az), tc.Case)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ const (
|
|||
ChargedIcon properties.Property = "charged_icon"
|
||||
)
|
||||
|
||||
func (b *Battery) template() string {
|
||||
func (b *Battery) Template() string {
|
||||
return "{{ if not .Error }}{{.Icon}}{{.Percentage}}{{ end }}{{.Error}}"
|
||||
}
|
||||
|
||||
func (b *Battery) enabled() bool {
|
||||
func (b *Battery) Enabled() bool {
|
||||
batteries, err := b.env.BatteryInfo()
|
||||
|
||||
if !b.enabledWhileError(err) {
|
||||
|
@ -105,7 +105,7 @@ func (b *Battery) mapMostLogicalState(currentState, newState battery.State) batt
|
|||
return newState
|
||||
}
|
||||
|
||||
func (b *Battery) init(props properties.Properties, env environment.Environment) {
|
||||
func (b *Battery) Init(props properties.Properties, env environment.Environment) {
|
||||
b.props = props
|
||||
b.env = env
|
||||
}
|
||||
|
|
|
@ -100,11 +100,11 @@ type Batch struct {
|
|||
TemperatureTrend float64 // diff between this and last, short term trend
|
||||
}
|
||||
|
||||
func (bf *Brewfather) template() string {
|
||||
func (bf *Brewfather) Template() string {
|
||||
return DefaultTemplate
|
||||
}
|
||||
|
||||
func (bf *Brewfather) enabled() bool {
|
||||
func (bf *Brewfather) Enabled() bool {
|
||||
data, err := bf.getResult()
|
||||
if err != nil {
|
||||
return false
|
||||
|
@ -326,7 +326,7 @@ func (bf *Brewfather) SGToPlato(sg float64) float64 {
|
|||
return math.Round(100*((135.997*sg*sg*sg)-(630.272*sg*sg)+(1111.14*sg)-616.868)) / 100 // 2 decimal places
|
||||
}
|
||||
|
||||
func (bf *Brewfather) init(props properties.Properties, env environment.Environment) {
|
||||
func (bf *Brewfather) Init(props properties.Properties, env environment.Environment) {
|
||||
bf.props = props
|
||||
bf.env = env
|
||||
}
|
||||
|
|
|
@ -159,14 +159,14 @@ func TestBrewfatherSegment(t *testing.T) {
|
|||
env: env,
|
||||
}
|
||||
|
||||
enabled := ns.enabled()
|
||||
enabled := ns.Enabled()
|
||||
assert.Equal(t, tc.ExpectedEnabled, enabled, tc.Case)
|
||||
if !enabled {
|
||||
continue
|
||||
}
|
||||
|
||||
if tc.Template == "" {
|
||||
tc.Template = ns.template()
|
||||
tc.Template = ns.Template()
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, ns), tc.Case)
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ const (
|
|||
Command properties.Property = "command"
|
||||
)
|
||||
|
||||
func (c *Cmd) template() string {
|
||||
func (c *Cmd) Template() string {
|
||||
return "{{ .Output }}"
|
||||
}
|
||||
|
||||
func (c *Cmd) enabled() bool {
|
||||
func (c *Cmd) Enabled() bool {
|
||||
shell := c.props.GetString(ExecutableShell, "bash")
|
||||
if !c.env.HasCommand(shell) {
|
||||
return false
|
||||
|
@ -53,7 +53,7 @@ func (c *Cmd) enabled() bool {
|
|||
return c.Output != ""
|
||||
}
|
||||
|
||||
func (c *Cmd) init(props properties.Properties, env environment.Environment) {
|
||||
func (c *Cmd) Init(props properties.Properties, env environment.Environment) {
|
||||
c.props = props
|
||||
c.env = env
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ func TestExecuteCommand(t *testing.T) {
|
|||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
enabled := c.Enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, "hello", renderTemplate(env, c.template(), c))
|
||||
assert.Equal(t, "hello", renderTemplate(env, c.Template(), c))
|
||||
}
|
||||
|
||||
func TestExecuteMultipleCommandsOrFirst(t *testing.T) {
|
||||
|
@ -37,9 +37,9 @@ func TestExecuteMultipleCommandsOrFirst(t *testing.T) {
|
|||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
enabled := c.Enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, "hello", renderTemplate(env, c.template(), c))
|
||||
assert.Equal(t, "hello", renderTemplate(env, c.Template(), c))
|
||||
}
|
||||
|
||||
func TestExecuteMultipleCommandsOrSecond(t *testing.T) {
|
||||
|
@ -54,9 +54,9 @@ func TestExecuteMultipleCommandsOrSecond(t *testing.T) {
|
|||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
enabled := c.Enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, "hello", renderTemplate(env, c.template(), c))
|
||||
assert.Equal(t, "hello", renderTemplate(env, c.Template(), c))
|
||||
}
|
||||
|
||||
func TestExecuteMultipleCommandsAnd(t *testing.T) {
|
||||
|
@ -71,9 +71,9 @@ func TestExecuteMultipleCommandsAnd(t *testing.T) {
|
|||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
enabled := c.Enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, "helloworld", renderTemplate(env, c.template(), c))
|
||||
assert.Equal(t, "helloworld", renderTemplate(env, c.Template(), c))
|
||||
}
|
||||
|
||||
func TestExecuteSingleCommandEmpty(t *testing.T) {
|
||||
|
@ -87,7 +87,7 @@ func TestExecuteSingleCommandEmpty(t *testing.T) {
|
|||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
enabled := c.Enabled()
|
||||
assert.False(t, enabled)
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ func TestExecuteSingleCommandNoCommandProperty(t *testing.T) {
|
|||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
enabled := c.Enabled()
|
||||
assert.True(t, enabled)
|
||||
assert.Equal(t, "no command specified", c.Output)
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ func TestExecuteMultipleCommandsAndDisabled(t *testing.T) {
|
|||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
enabled := c.Enabled()
|
||||
assert.False(t, enabled)
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,6 @@ func TestExecuteMultipleCommandsOrDisabled(t *testing.T) {
|
|||
props: props,
|
||||
env: env,
|
||||
}
|
||||
enabled := c.enabled()
|
||||
enabled := c.Enabled()
|
||||
assert.False(t, enabled)
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ type Crystal struct {
|
|||
language
|
||||
}
|
||||
|
||||
func (c *Crystal) template() string {
|
||||
func (c *Crystal) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (c *Crystal) init(props properties.Properties, env environment.Environment) {
|
||||
func (c *Crystal) Init(props properties.Properties, env environment.Environment) {
|
||||
c.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -29,6 +29,6 @@ func (c *Crystal) init(props properties.Properties, env environment.Environment)
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Crystal) enabled() bool {
|
||||
return c.language.enabled()
|
||||
func (c *Crystal) Enabled() bool {
|
||||
return c.language.Enabled()
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ func TestCrystal(t *testing.T) {
|
|||
}
|
||||
env, props := getMockedLanguageEnv(params)
|
||||
c := &Crystal{}
|
||||
c.init(props, env)
|
||||
assert.True(t, c.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, c.template(), c), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
c.Init(props, env)
|
||||
assert.True(t, c.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, c.Template(), c), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ type Dart struct {
|
|||
language
|
||||
}
|
||||
|
||||
func (d *Dart) template() string {
|
||||
func (d *Dart) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (d *Dart) init(props properties.Properties, env environment.Environment) {
|
||||
func (d *Dart) Init(props properties.Properties, env environment.Environment) {
|
||||
d.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -29,6 +29,6 @@ func (d *Dart) init(props properties.Properties, env environment.Environment) {
|
|||
}
|
||||
}
|
||||
|
||||
func (d *Dart) enabled() bool {
|
||||
return d.language.enabled()
|
||||
func (d *Dart) Enabled() bool {
|
||||
return d.language.Enabled()
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ func TestDart(t *testing.T) {
|
|||
}
|
||||
env, props := getMockedLanguageEnv(params)
|
||||
d := &Dart{}
|
||||
d.init(props, env)
|
||||
assert.True(t, d.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, d.template(), d), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
d.Init(props, env)
|
||||
assert.True(t, d.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, d.Template(), d), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ type Dotnet struct {
|
|||
Unsupported bool
|
||||
}
|
||||
|
||||
func (d *Dotnet) template() string {
|
||||
func (d *Dotnet) Template() string {
|
||||
return "{{ if .Unsupported }}\uf071{{ else }}{{ .Full }}{{ end }}"
|
||||
}
|
||||
|
||||
func (d *Dotnet) init(props properties.Properties, env environment.Environment) {
|
||||
func (d *Dotnet) Init(props properties.Properties, env environment.Environment) {
|
||||
d.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -32,8 +32,8 @@ func (d *Dotnet) init(props properties.Properties, env environment.Environment)
|
|||
}
|
||||
}
|
||||
|
||||
func (d *Dotnet) enabled() bool {
|
||||
enabled := d.language.enabled()
|
||||
func (d *Dotnet) Enabled() bool {
|
||||
enabled := d.language.Enabled()
|
||||
if !enabled {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ func TestDotnetSegment(t *testing.T) {
|
|||
properties.FetchVersion: tc.FetchVersion,
|
||||
}
|
||||
dotnet := &Dotnet{}
|
||||
dotnet.init(props, env)
|
||||
assert.True(t, dotnet.enabled())
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, dotnet.template(), dotnet), tc.Case)
|
||||
dotnet.Init(props, env)
|
||||
assert.True(t, dotnet.Enabled())
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, dotnet.Template(), dotnet), tc.Case)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ const (
|
|||
hoursPerDay = 24
|
||||
)
|
||||
|
||||
func (t *Executiontime) enabled() bool {
|
||||
func (t *Executiontime) Enabled() bool {
|
||||
alwaysEnabled := t.props.GetBool(properties.AlwaysEnabled, false)
|
||||
executionTimeMs := t.env.ExecutionTime()
|
||||
thresholdMs := t.props.GetFloat64(ThresholdProperty, float64(500))
|
||||
|
@ -61,11 +61,11 @@ func (t *Executiontime) enabled() bool {
|
|||
return t.FormattedMs != ""
|
||||
}
|
||||
|
||||
func (t *Executiontime) template() string {
|
||||
func (t *Executiontime) Template() string {
|
||||
return "{{ .FormattedMs }}"
|
||||
}
|
||||
|
||||
func (t *Executiontime) init(props properties.Properties, env environment.Environment) {
|
||||
func (t *Executiontime) Init(props properties.Properties, env environment.Environment) {
|
||||
t.props = props
|
||||
t.env = env
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func TestExecutionTimeWriterDefaultThresholdEnabled(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
assert.True(t, executionTime.enabled())
|
||||
assert.True(t, executionTime.Enabled())
|
||||
}
|
||||
|
||||
func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) {
|
||||
|
@ -26,7 +26,7 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
assert.False(t, executionTime.enabled())
|
||||
assert.False(t, executionTime.Enabled())
|
||||
}
|
||||
|
||||
func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
|
||||
|
@ -39,7 +39,7 @@ func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
|
|||
env: env,
|
||||
props: props,
|
||||
}
|
||||
assert.True(t, executionTime.enabled())
|
||||
assert.True(t, executionTime.Enabled())
|
||||
}
|
||||
|
||||
func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) {
|
||||
|
@ -52,7 +52,7 @@ func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) {
|
|||
env: env,
|
||||
props: props,
|
||||
}
|
||||
assert.False(t, executionTime.enabled())
|
||||
assert.False(t, executionTime.Enabled())
|
||||
}
|
||||
|
||||
func TestExecutionTimeWriterDuration(t *testing.T) {
|
||||
|
@ -64,7 +64,7 @@ func TestExecutionTimeWriterDuration(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
executionTime.enabled()
|
||||
executionTime.Enabled()
|
||||
assert.Equal(t, expected, executionTime.FormattedMs)
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ func TestExecutionTimeWriterDuration2(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
executionTime.enabled()
|
||||
executionTime.Enabled()
|
||||
assert.Equal(t, expected, executionTime.FormattedMs)
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,11 @@ type Exit struct {
|
|||
Text string
|
||||
}
|
||||
|
||||
func (e *Exit) template() string {
|
||||
func (e *Exit) Template() string {
|
||||
return "{{ .Text }}"
|
||||
}
|
||||
|
||||
func (e *Exit) enabled() bool {
|
||||
func (e *Exit) Enabled() bool {
|
||||
e.Text = e.getMeaningFromExitCode(e.env.ErrorCode())
|
||||
if e.props.GetBool(properties.AlwaysEnabled, false) {
|
||||
return true
|
||||
|
@ -25,7 +25,7 @@ func (e *Exit) enabled() bool {
|
|||
return e.env.ErrorCode() != 0
|
||||
}
|
||||
|
||||
func (e *Exit) init(props properties.Properties, env environment.Environment) {
|
||||
func (e *Exit) Init(props properties.Properties, env environment.Environment) {
|
||||
e.props = props
|
||||
e.env = env
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestExitWriterEnabled(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
assert.Equal(t, tc.Expected, e.enabled())
|
||||
assert.Equal(t, tc.Expected, e.Enabled())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,11 +107,11 @@ const (
|
|||
BRANCHPREFIX = "ref: refs/heads/"
|
||||
)
|
||||
|
||||
func (g *Git) template() string {
|
||||
func (g *Git) Template() string {
|
||||
return "{{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}" // nolint: lll
|
||||
}
|
||||
|
||||
func (g *Git) enabled() bool {
|
||||
func (g *Git) Enabled() bool {
|
||||
if !g.shouldDisplay() {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ func TestEnabledGitNotFound(t *testing.T) {
|
|||
props: properties.Map{},
|
||||
},
|
||||
}
|
||||
assert.False(t, g.enabled())
|
||||
assert.False(t, g.Enabled())
|
||||
}
|
||||
|
||||
func TestEnabledInWorkingDirectory(t *testing.T) {
|
||||
|
@ -50,7 +50,7 @@ func TestEnabledInWorkingDirectory(t *testing.T) {
|
|||
props: properties.Map{},
|
||||
},
|
||||
}
|
||||
assert.True(t, g.enabled())
|
||||
assert.True(t, g.Enabled())
|
||||
assert.Equal(t, fileInfo.Path, g.gitWorkingFolder)
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ func TestEnabledInWorkingTree(t *testing.T) {
|
|||
props: properties.Map{},
|
||||
},
|
||||
}
|
||||
assert.True(t, g.enabled())
|
||||
assert.True(t, g.Enabled())
|
||||
assert.Equal(t, "/dev/real_folder/.git/worktrees/folder_worktree", g.gitWorkingFolder)
|
||||
assert.Equal(t, "/dev/folder_worktree", g.gitRealFolder)
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ func TestEnabledInSubmodule(t *testing.T) {
|
|||
props: properties.Map{},
|
||||
},
|
||||
}
|
||||
assert.True(t, g.enabled())
|
||||
assert.True(t, g.Enabled())
|
||||
assert.Equal(t, "/dev/parent/test-submodule/../.git/modules/test-submodule", g.gitWorkingFolder)
|
||||
assert.Equal(t, "/dev/parent/test-submodule/../.git/modules/test-submodule", g.gitRealFolder)
|
||||
assert.Equal(t, "/dev/parent/test-submodule/../.git/modules/test-submodule", g.gitRootFolder)
|
||||
|
|
|
@ -15,11 +15,11 @@ const (
|
|||
ParseModFile properties.Property = "parse_mod_file"
|
||||
)
|
||||
|
||||
func (g *Golang) template() string {
|
||||
func (g *Golang) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (g *Golang) init(props properties.Properties, env environment.Environment) {
|
||||
func (g *Golang) Init(props properties.Properties, env environment.Environment) {
|
||||
g.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -55,6 +55,6 @@ func (g *Golang) getVersion() (string, error) {
|
|||
return file.Go.Version, nil
|
||||
}
|
||||
|
||||
func (g *Golang) enabled() bool {
|
||||
return g.language.enabled()
|
||||
func (g *Golang) Enabled() bool {
|
||||
return g.language.Enabled()
|
||||
}
|
||||
|
|
|
@ -87,8 +87,8 @@ func TestGolang(t *testing.T) {
|
|||
env.On("FileContent", fileInfo.Path).Return(content)
|
||||
}
|
||||
g := &Golang{}
|
||||
g.init(props, env)
|
||||
assert.True(t, g.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, g.template(), g), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
g.Init(props, env)
|
||||
assert.True(t, g.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, g.Template(), g), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ const (
|
|||
IpifyURL properties.Property = "url"
|
||||
)
|
||||
|
||||
func (i *IPify) template() string {
|
||||
func (i *IPify) Template() string {
|
||||
return "{{ .IP }}"
|
||||
}
|
||||
|
||||
func (i *IPify) enabled() bool {
|
||||
func (i *IPify) Enabled() bool {
|
||||
ip, err := i.getResult()
|
||||
if err != nil {
|
||||
return false
|
||||
|
@ -60,7 +60,7 @@ func (i *IPify) getResult() (string, error) {
|
|||
return response, nil
|
||||
}
|
||||
|
||||
func (i *IPify) init(props properties.Properties, env environment.Environment) {
|
||||
func (i *IPify) Init(props properties.Properties, env environment.Environment) {
|
||||
i.props = props
|
||||
i.env = env
|
||||
}
|
||||
|
|
|
@ -55,14 +55,14 @@ func TestIpifySegment(t *testing.T) {
|
|||
env: env,
|
||||
}
|
||||
|
||||
enabled := ipify.enabled()
|
||||
enabled := ipify.Enabled()
|
||||
assert.Equal(t, tc.ExpectedEnabled, enabled, tc.Case)
|
||||
if !enabled {
|
||||
continue
|
||||
}
|
||||
|
||||
if tc.Template == "" {
|
||||
tc.Template = ipify.template()
|
||||
tc.Template = ipify.Template()
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, ipify), tc.Case)
|
||||
}
|
||||
|
|
|
@ -10,11 +10,11 @@ type Java struct {
|
|||
language
|
||||
}
|
||||
|
||||
func (j *Java) template() string {
|
||||
func (j *Java) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (j *Java) init(props properties.Properties, env environment.Environment) {
|
||||
func (j *Java) Init(props properties.Properties, env environment.Environment) {
|
||||
javaRegex := `(?: JRE)(?: \(.*\))? \((?P<version>(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?(?:\.(?P<patch>[0-9]+))?).*\),`
|
||||
javaCmd := &cmd{
|
||||
executable: "java",
|
||||
|
@ -56,6 +56,6 @@ func (j *Java) init(props properties.Properties, env environment.Environment) {
|
|||
j.language.commands = []*cmd{javaCmd}
|
||||
}
|
||||
|
||||
func (j *Java) enabled() bool {
|
||||
return j.language.enabled()
|
||||
func (j *Java) Enabled() bool {
|
||||
return j.language.Enabled()
|
||||
}
|
||||
|
|
|
@ -72,8 +72,8 @@ func TestJava(t *testing.T) {
|
|||
properties.FetchVersion: true,
|
||||
}
|
||||
j := &Java{}
|
||||
j.init(props, env)
|
||||
assert.True(t, j.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, j.template(), j), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
j.Init(props, env)
|
||||
assert.True(t, j.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, j.Template(), j), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ type Julia struct {
|
|||
language
|
||||
}
|
||||
|
||||
func (j *Julia) template() string {
|
||||
func (j *Julia) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (j *Julia) init(props properties.Properties, env environment.Environment) {
|
||||
func (j *Julia) Init(props properties.Properties, env environment.Environment) {
|
||||
j.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -29,6 +29,6 @@ func (j *Julia) init(props properties.Properties, env environment.Environment) {
|
|||
}
|
||||
}
|
||||
|
||||
func (j *Julia) enabled() bool {
|
||||
return j.language.enabled()
|
||||
func (j *Julia) Enabled() bool {
|
||||
return j.language.Enabled()
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ func TestJulia(t *testing.T) {
|
|||
}
|
||||
env, props := getMockedLanguageEnv(params)
|
||||
j := &Julia{}
|
||||
j.init(props, env)
|
||||
assert.True(t, j.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, j.template(), j), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
j.Init(props, env)
|
||||
assert.True(t, j.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, j.Template(), j), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,16 +34,16 @@ type KubeContext struct {
|
|||
Namespace string `yaml:"namespace"`
|
||||
}
|
||||
|
||||
func (k *Kubectl) template() string {
|
||||
func (k *Kubectl) Template() string {
|
||||
return "{{ .Context }}{{ if .Namespace }} :: {{ .Namespace }}{{ end }}"
|
||||
}
|
||||
|
||||
func (k *Kubectl) init(props properties.Properties, env environment.Environment) {
|
||||
func (k *Kubectl) Init(props properties.Properties, env environment.Environment) {
|
||||
k.props = props
|
||||
k.env = env
|
||||
}
|
||||
|
||||
func (k *Kubectl) enabled() bool {
|
||||
func (k *Kubectl) Enabled() bool {
|
||||
parseKubeConfig := k.props.GetBool(ParseKubeConfig, false)
|
||||
if parseKubeConfig {
|
||||
return k.doParseKubeConfig()
|
||||
|
|
|
@ -136,7 +136,7 @@ func TestKubectlSegment(t *testing.T) {
|
|||
ParseKubeConfig: tc.ParseKubeConfig,
|
||||
},
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedEnabled, k.enabled(), tc.Case)
|
||||
assert.Equal(t, tc.ExpectedEnabled, k.Enabled(), tc.Case)
|
||||
if tc.ExpectedEnabled {
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, k), tc.Case)
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ const (
|
|||
LanguageExtensions properties.Property = "extensions"
|
||||
)
|
||||
|
||||
func (l *language) enabled() bool {
|
||||
func (l *language) Enabled() bool {
|
||||
// override default extensions if needed
|
||||
l.extensions = l.props.GetStringArray(LanguageExtensions, l.extensions)
|
||||
inHomeDir := func() bool {
|
||||
|
|
|
@ -82,7 +82,7 @@ func TestLanguageFilesFoundButNoCommandAndVersionAndDisplayVersion(t *testing.T)
|
|||
enabledExtensions: []string{uni},
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, "", lang.Error, "unicorn is not available")
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ func TestLanguageFilesFoundButNoCommandAndVersionAndDontDisplayVersion(t *testin
|
|||
properties: props,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled(), "unicorn is not available")
|
||||
assert.True(t, lang.Enabled(), "unicorn is not available")
|
||||
}
|
||||
|
||||
func TestLanguageFilesFoundButNoCommandAndNoVersion(t *testing.T) {
|
||||
|
@ -117,7 +117,7 @@ func TestLanguageFilesFoundButNoCommandAndNoVersion(t *testing.T) {
|
|||
enabledExtensions: []string{uni},
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled(), "unicorn is not available")
|
||||
assert.True(t, lang.Enabled(), "unicorn is not available")
|
||||
}
|
||||
|
||||
func TestLanguageDisabledNoFiles(t *testing.T) {
|
||||
|
@ -133,7 +133,7 @@ func TestLanguageDisabledNoFiles(t *testing.T) {
|
|||
enabledCommands: []string{"unicorn"},
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.False(t, lang.enabled(), "no files in the current directory")
|
||||
assert.False(t, lang.Enabled(), "no files in the current directory")
|
||||
}
|
||||
|
||||
func TestLanguageEnabledOneExtensionFound(t *testing.T) {
|
||||
|
@ -151,7 +151,7 @@ func TestLanguageEnabledOneExtensionFound(t *testing.T) {
|
|||
version: universion,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, universion, lang.Full, "unicorn is available and uni files are found")
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ func TestLanguageDisabledInHome(t *testing.T) {
|
|||
inHome: true,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.False(t, lang.enabled())
|
||||
assert.False(t, lang.Enabled())
|
||||
}
|
||||
|
||||
func TestLanguageEnabledSecondExtensionFound(t *testing.T) {
|
||||
|
@ -189,7 +189,7 @@ func TestLanguageEnabledSecondExtensionFound(t *testing.T) {
|
|||
version: universion,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, universion, lang.Full, "unicorn is available and corn files are found")
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,7 @@ func TestLanguageEnabledSecondCommand(t *testing.T) {
|
|||
version: universion,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, universion, lang.Full, "unicorn is available and corn files are found")
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ func TestLanguageEnabledAllExtensionsFound(t *testing.T) {
|
|||
version: universion,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, universion, lang.Full, "unicorn is available and uni and corn files are found")
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ func TestLanguageEnabledNoVersion(t *testing.T) {
|
|||
properties: props,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, "", lang.Full, "unicorn is available and uni and corn files are found")
|
||||
}
|
||||
|
||||
|
@ -272,7 +272,7 @@ func TestLanguageEnabledMissingCommand(t *testing.T) {
|
|||
properties: props,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, "", lang.Full, "unicorn is unavailable and uni and corn files are found")
|
||||
}
|
||||
|
||||
|
@ -295,7 +295,7 @@ func TestLanguageEnabledNoVersionData(t *testing.T) {
|
|||
properties: props,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, "", lang.Full)
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ func TestLanguageEnabledMissingCommandCustomText(t *testing.T) {
|
|||
properties: props,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, expected, lang.Error, "unicorn is available and uni and corn files are found")
|
||||
}
|
||||
|
||||
|
@ -331,7 +331,7 @@ func TestLanguageEnabledMissingCommandCustomTextHideError(t *testing.T) {
|
|||
properties: props,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, "", lang.Full)
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,7 @@ func TestLanguageEnabledCommandExitCode(t *testing.T) {
|
|||
expectedError: &environment.CommandError{ExitCode: expected},
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, "err executing uni with [--version]", lang.Error)
|
||||
assert.Equal(t, expected, lang.exitCode)
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ func TestLanguageHyperlinkEnabled(t *testing.T) {
|
|||
properties: properties.Map{},
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, "https://unicor.org/doc/1.3.307", lang.version.URL)
|
||||
}
|
||||
|
||||
|
@ -405,7 +405,7 @@ func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) {
|
|||
properties: properties.Map{},
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.True(t, lang.enabled())
|
||||
assert.True(t, lang.Enabled())
|
||||
assert.Equal(t, "err parsing info from corn with 1.3.307", lang.Error)
|
||||
}
|
||||
|
||||
|
@ -438,6 +438,6 @@ func TestLanguageEnabledInHome(t *testing.T) {
|
|||
inHome: true,
|
||||
}
|
||||
lang := bootStrapLanguageTest(args)
|
||||
assert.Equal(t, tc.ExpectedEnabled, lang.enabled(), tc.Case)
|
||||
assert.Equal(t, tc.ExpectedEnabled, lang.Enabled(), tc.Case)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,11 +24,11 @@ type VersionInfo struct {
|
|||
SimpleVersion string `json:"SimpleVersion"`
|
||||
}
|
||||
|
||||
func (n *Nbgv) template() string {
|
||||
func (n *Nbgv) Template() string {
|
||||
return "{{ .Version }}"
|
||||
}
|
||||
|
||||
func (n *Nbgv) enabled() bool {
|
||||
func (n *Nbgv) Enabled() bool {
|
||||
nbgv := "nbgv"
|
||||
if !n.env.HasCommand(nbgv) {
|
||||
return false
|
||||
|
@ -45,7 +45,7 @@ func (n *Nbgv) enabled() bool {
|
|||
return n.VersionInfo.VersionFileFound
|
||||
}
|
||||
|
||||
func (n *Nbgv) init(props properties.Properties, env environment.Environment) {
|
||||
func (n *Nbgv) Init(props properties.Properties, env environment.Environment) {
|
||||
n.props = props
|
||||
n.env = env
|
||||
}
|
||||
|
|
|
@ -66,10 +66,10 @@ func TestNbgv(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
enabled := nbgv.enabled()
|
||||
enabled := nbgv.Enabled()
|
||||
assert.Equal(t, tc.ExpectedEnabled, enabled, tc.Case)
|
||||
if tc.Template == "" {
|
||||
tc.Template = nbgv.template()
|
||||
tc.Template = nbgv.Template()
|
||||
}
|
||||
if enabled {
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, nbgv), tc.Case)
|
||||
|
|
|
@ -47,11 +47,11 @@ type NightscoutData struct {
|
|||
Mills int64 `json:"mills"`
|
||||
}
|
||||
|
||||
func (ns *Nightscout) template() string {
|
||||
func (ns *Nightscout) Template() string {
|
||||
return "{{ .Sgv }}"
|
||||
}
|
||||
|
||||
func (ns *Nightscout) enabled() bool {
|
||||
func (ns *Nightscout) Enabled() bool {
|
||||
data, err := ns.getResult()
|
||||
if err != nil {
|
||||
return false
|
||||
|
@ -139,7 +139,7 @@ func (ns *Nightscout) getResult() (*NightscoutData, error) {
|
|||
return data, nil
|
||||
}
|
||||
|
||||
func (ns *Nightscout) init(props properties.Properties, env environment.Environment) {
|
||||
func (ns *Nightscout) Init(props properties.Properties, env environment.Environment) {
|
||||
ns.props = props
|
||||
ns.env = env
|
||||
}
|
||||
|
|
|
@ -149,14 +149,14 @@ func TestNSSegment(t *testing.T) {
|
|||
env: env,
|
||||
}
|
||||
|
||||
enabled := ns.enabled()
|
||||
enabled := ns.Enabled()
|
||||
assert.Equal(t, tc.ExpectedEnabled, enabled, tc.Case)
|
||||
if !enabled {
|
||||
continue
|
||||
}
|
||||
|
||||
if tc.Template == "" {
|
||||
tc.Template = ns.template()
|
||||
tc.Template = ns.Template()
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, ns), tc.Case)
|
||||
}
|
||||
|
|
|
@ -22,11 +22,11 @@ const (
|
|||
FetchPackageManager properties.Property = "fetch_package_manager"
|
||||
)
|
||||
|
||||
func (n *Node) template() string {
|
||||
func (n *Node) Template() string {
|
||||
return "{{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }}"
|
||||
}
|
||||
|
||||
func (n *Node) init(props properties.Properties, env environment.Environment) {
|
||||
func (n *Node) Init(props properties.Properties, env environment.Environment) {
|
||||
n.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -44,8 +44,8 @@ func (n *Node) init(props properties.Properties, env environment.Environment) {
|
|||
}
|
||||
}
|
||||
|
||||
func (n *Node) enabled() bool {
|
||||
return n.language.enabled()
|
||||
func (n *Node) Enabled() bool {
|
||||
return n.language.Enabled()
|
||||
}
|
||||
|
||||
func (n *Node) loadContext() {
|
||||
|
|
|
@ -61,11 +61,11 @@ const (
|
|||
DisplayDistroName properties.Property = "display_distro_name"
|
||||
)
|
||||
|
||||
func (oi *Os) template() string {
|
||||
func (oi *Os) Template() string {
|
||||
return "{{ if .WSL }}WSL at {{ end }}{{.Icon}}"
|
||||
}
|
||||
|
||||
func (oi *Os) enabled() bool {
|
||||
func (oi *Os) Enabled() bool {
|
||||
goos := oi.env.GOOS()
|
||||
switch goos {
|
||||
case environment.WindowsPlatform:
|
||||
|
@ -130,7 +130,7 @@ func (oi *Os) getDistroIcon(distro string) string {
|
|||
return oi.props.GetString(Linux, "\uF17C")
|
||||
}
|
||||
|
||||
func (oi *Os) init(props properties.Properties, env environment.Environment) {
|
||||
func (oi *Os) Init(props properties.Properties, env environment.Environment) {
|
||||
oi.props = props
|
||||
oi.env = env
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ func TestOSInfo(t *testing.T) {
|
|||
MacOS: "darwin",
|
||||
},
|
||||
}
|
||||
_ = osInfo.enabled()
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, osInfo.template(), osInfo), tc.Case)
|
||||
_ = osInfo.Enabled()
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, osInfo.Template(), osInfo), tc.Case)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,12 +48,12 @@ type owmDataResponse struct {
|
|||
temperature `json:"main"`
|
||||
}
|
||||
|
||||
func (d *Owm) enabled() bool {
|
||||
func (d *Owm) Enabled() bool {
|
||||
err := d.setStatus()
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (d *Owm) template() string {
|
||||
func (d *Owm) Template() string {
|
||||
return "{{ .Weather }} ({{ .Temperature }}{{ .UnitIcon }})"
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ func (d *Owm) setStatus() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *Owm) init(props properties.Properties, env environment.Environment) {
|
||||
func (d *Owm) Init(props properties.Properties, env environment.Environment) {
|
||||
d.props = props
|
||||
d.env = env
|
||||
}
|
||||
|
|
|
@ -67,14 +67,14 @@ func TestOWMSegmentSingle(t *testing.T) {
|
|||
env: env,
|
||||
}
|
||||
|
||||
enabled := o.enabled()
|
||||
enabled := o.Enabled()
|
||||
assert.Equal(t, tc.ExpectedEnabled, enabled, tc.Case)
|
||||
if !enabled {
|
||||
continue
|
||||
}
|
||||
|
||||
if tc.Template == "" {
|
||||
tc.Template = o.template()
|
||||
tc.Template = o.Template()
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, o), tc.Case)
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func TestOWMSegmentIcons(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Nil(t, o.setStatus())
|
||||
assert.Equal(t, expectedString, renderTemplate(env, o.template(), o), tc.Case)
|
||||
assert.Equal(t, expectedString, renderTemplate(env, o.Template(), o), tc.Case)
|
||||
}
|
||||
|
||||
// test with hyperlink enabled
|
||||
|
@ -244,7 +244,7 @@ func TestOWMSegmentFromCache(t *testing.T) {
|
|||
env.On("Cache").Return(cache)
|
||||
|
||||
assert.Nil(t, o.setStatus())
|
||||
assert.Equal(t, expectedString, renderTemplate(env, o.template(), o), "should return the cached response")
|
||||
assert.Equal(t, expectedString, renderTemplate(env, o.Template(), o), "should return the cached response")
|
||||
}
|
||||
|
||||
func TestOWMSegmentFromCacheWithHyperlink(t *testing.T) {
|
||||
|
|
|
@ -56,11 +56,11 @@ const (
|
|||
MaxDepth properties.Property = "max_depth"
|
||||
)
|
||||
|
||||
func (pt *Path) template() string {
|
||||
func (pt *Path) Template() string {
|
||||
return "{{ .Path }}"
|
||||
}
|
||||
|
||||
func (pt *Path) enabled() bool {
|
||||
func (pt *Path) Enabled() bool {
|
||||
pt.pwd = pt.env.Pwd()
|
||||
switch style := pt.props.GetString(properties.Style, Agnoster); style {
|
||||
case Agnoster:
|
||||
|
@ -103,7 +103,7 @@ func (pt *Path) formatWindowsDrive(pwd string) string {
|
|||
return pwd + "\\"
|
||||
}
|
||||
|
||||
func (pt *Path) init(props properties.Properties, env environment.Environment) {
|
||||
func (pt *Path) Init(props properties.Properties, env environment.Environment) {
|
||||
pt.props = props
|
||||
pt.env = env
|
||||
}
|
||||
|
|
|
@ -259,7 +259,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
|||
MaxDepth: tc.MaxDepth,
|
||||
},
|
||||
}
|
||||
_ = path.enabled()
|
||||
_ = path.Enabled()
|
||||
got := renderTemplate(env, "{{ .Path }}", path)
|
||||
assert.Equal(t, tc.Expected, got)
|
||||
}
|
||||
|
@ -388,7 +388,7 @@ func TestGetFullPath(t *testing.T) {
|
|||
env: env,
|
||||
props: props,
|
||||
}
|
||||
_ = path.enabled()
|
||||
_ = path.Enabled()
|
||||
got := renderTemplate(env, tc.Template, path)
|
||||
assert.Equal(t, tc.Expected, got)
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ type Php struct {
|
|||
language
|
||||
}
|
||||
|
||||
func (p *Php) template() string {
|
||||
func (p *Php) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (p *Php) init(props properties.Properties, env environment.Environment) {
|
||||
func (p *Php) Init(props properties.Properties, env environment.Environment) {
|
||||
p.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -29,6 +29,6 @@ func (p *Php) init(props properties.Properties, env environment.Environment) {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Php) enabled() bool {
|
||||
return p.language.enabled()
|
||||
func (p *Php) Enabled() bool {
|
||||
return p.language.Enabled()
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ func TestPhp(t *testing.T) {
|
|||
}
|
||||
env, props := getMockedLanguageEnv(params)
|
||||
j := &Php{}
|
||||
j.init(props, env)
|
||||
assert.True(t, j.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, j.template(), j), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
j.Init(props, env)
|
||||
assert.True(t, j.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, j.Template(), j), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,16 +37,16 @@ type Plastic struct {
|
|||
plasticWorkspaceFolder string // root folder of workspace
|
||||
}
|
||||
|
||||
func (p *Plastic) init(props properties.Properties, env environment.Environment) {
|
||||
func (p *Plastic) Init(props properties.Properties, env environment.Environment) {
|
||||
p.props = props
|
||||
p.env = env
|
||||
}
|
||||
|
||||
func (p *Plastic) template() string {
|
||||
func (p *Plastic) Template() string {
|
||||
return "{{ .Selector }}"
|
||||
}
|
||||
|
||||
func (p *Plastic) enabled() bool {
|
||||
func (p *Plastic) Enabled() bool {
|
||||
if !p.env.HasCommand("cm") {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ func TestPlasticEnabledNotFound(t *testing.T) {
|
|||
props: properties.Map{},
|
||||
},
|
||||
}
|
||||
assert.False(t, p.enabled())
|
||||
assert.False(t, p.Enabled())
|
||||
}
|
||||
|
||||
func TestPlasticEnabledInWorkspaceDirectory(t *testing.T) {
|
||||
|
@ -41,7 +41,7 @@ func TestPlasticEnabledInWorkspaceDirectory(t *testing.T) {
|
|||
props: properties.Map{},
|
||||
},
|
||||
}
|
||||
assert.True(t, p.enabled())
|
||||
assert.True(t, p.Enabled())
|
||||
assert.Equal(t, fileInfo.ParentFolder, p.plasticWorkspaceFolder)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,17 +17,17 @@ const (
|
|||
poshGitEnv = "POSH_GIT_STATUS"
|
||||
)
|
||||
|
||||
func (p *PoshGit) template() string {
|
||||
func (p *PoshGit) Template() string {
|
||||
return "{{ .Status }}"
|
||||
}
|
||||
|
||||
func (p *PoshGit) enabled() bool {
|
||||
func (p *PoshGit) Enabled() bool {
|
||||
status := p.env.Getenv(poshGitEnv)
|
||||
p.Status = strings.TrimSpace(status)
|
||||
return p.Status != ""
|
||||
}
|
||||
|
||||
func (p *PoshGit) init(props properties.Properties, env environment.Environment) {
|
||||
func (p *PoshGit) Init(props properties.Properties, env environment.Environment) {
|
||||
p.props = props
|
||||
p.env = env
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ func TestPoshGitSegment(t *testing.T) {
|
|||
env: env,
|
||||
props: &properties.Map{},
|
||||
}
|
||||
assert.Equal(t, tc.Enabled, p.enabled(), tc.Case)
|
||||
assert.Equal(t, tc.Enabled, p.Enabled(), tc.Case)
|
||||
if tc.Enabled {
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, p.template(), p), tc.Case)
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, p.Template(), p), tc.Case)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ const (
|
|||
FetchVirtualEnv properties.Property = "fetch_virtual_env"
|
||||
)
|
||||
|
||||
func (p *Python) template() string {
|
||||
func (p *Python) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (p *Python) init(props properties.Properties, env environment.Environment) {
|
||||
func (p *Python) Init(props properties.Properties, env environment.Environment) {
|
||||
p.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -45,8 +45,8 @@ func (p *Python) init(props properties.Properties, env environment.Environment)
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Python) enabled() bool {
|
||||
return p.language.enabled()
|
||||
func (p *Python) Enabled() bool {
|
||||
return p.language.Enabled()
|
||||
}
|
||||
|
||||
func (p *Python) loadContext() {
|
||||
|
|
|
@ -63,8 +63,8 @@ func TestPythonTemplate(t *testing.T) {
|
|||
Env: make(map[string]string),
|
||||
})
|
||||
python := &Python{}
|
||||
python.init(props, env)
|
||||
assert.Equal(t, !tc.ExpectedDisabled, python.enabled(), tc.Case)
|
||||
python.Init(props, env)
|
||||
assert.Equal(t, !tc.ExpectedDisabled, python.Enabled(), tc.Case)
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, tc.Template, python), tc.Case)
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func TestPythonPythonInContext(t *testing.T) {
|
|||
env.On("Getenv", "CONDA_DEFAULT_ENV").Return("")
|
||||
env.On("Getenv", "PYENV_VERSION").Return("")
|
||||
python := &Python{}
|
||||
python.init(properties.Map{}, env)
|
||||
python.Init(properties.Map{}, env)
|
||||
python.loadContext()
|
||||
assert.Equal(t, tc.Expected, python.inContext())
|
||||
}
|
||||
|
|
|
@ -10,15 +10,15 @@ type Root struct {
|
|||
env environment.Environment
|
||||
}
|
||||
|
||||
func (rt *Root) template() string {
|
||||
func (rt *Root) Template() string {
|
||||
return "\uF0E7"
|
||||
}
|
||||
|
||||
func (rt *Root) enabled() bool {
|
||||
func (rt *Root) Enabled() bool {
|
||||
return rt.env.Root()
|
||||
}
|
||||
|
||||
func (rt *Root) init(props properties.Properties, env environment.Environment) {
|
||||
func (rt *Root) Init(props properties.Properties, env environment.Environment) {
|
||||
rt.props = props
|
||||
rt.env = env
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ type Ruby struct {
|
|||
language
|
||||
}
|
||||
|
||||
func (r *Ruby) template() string {
|
||||
func (r *Ruby) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (r *Ruby) init(props properties.Properties, env environment.Environment) {
|
||||
func (r *Ruby) Init(props properties.Properties, env environment.Environment) {
|
||||
r.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -48,8 +48,8 @@ func (r *Ruby) init(props properties.Properties, env environment.Environment) {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Ruby) enabled() bool {
|
||||
enabled := r.language.enabled()
|
||||
func (r *Ruby) Enabled() bool {
|
||||
enabled := r.language.Enabled()
|
||||
// this happens when no version is set
|
||||
if r.Full == "______" {
|
||||
r.Full = ""
|
||||
|
|
|
@ -104,8 +104,8 @@ func TestRuby(t *testing.T) {
|
|||
properties.FetchVersion: tc.FetchVersion,
|
||||
}
|
||||
ruby := &Ruby{}
|
||||
ruby.init(props, env)
|
||||
assert.Equal(t, tc.ExpectedEnabled, ruby.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, ruby.template(), ruby), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
ruby.Init(props, env)
|
||||
assert.Equal(t, tc.ExpectedEnabled, ruby.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, ruby.Template(), ruby), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ type Rust struct {
|
|||
language
|
||||
}
|
||||
|
||||
func (r *Rust) template() string {
|
||||
func (r *Rust) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (r *Rust) init(props properties.Properties, env environment.Environment) {
|
||||
func (r *Rust) Init(props properties.Properties, env environment.Environment) {
|
||||
r.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
|
@ -28,6 +28,6 @@ func (r *Rust) init(props properties.Properties, env environment.Environment) {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Rust) enabled() bool {
|
||||
return r.language.enabled()
|
||||
func (r *Rust) Enabled() bool {
|
||||
return r.language.Enabled()
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ func TestRust(t *testing.T) {
|
|||
}
|
||||
env, props := getMockedLanguageEnv(params)
|
||||
r := &Rust{}
|
||||
r.init(props, env)
|
||||
assert.True(t, r.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, r.template(), r), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
r.Init(props, env)
|
||||
assert.True(t, r.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, r.Template(), r), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,16 +16,16 @@ type Session struct {
|
|||
DefaultUserName string
|
||||
}
|
||||
|
||||
func (s *Session) enabled() bool {
|
||||
func (s *Session) Enabled() bool {
|
||||
s.SSHSession = s.activeSSHSession()
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Session) template() string {
|
||||
func (s *Session) Template() string {
|
||||
return "{{ .UserName }}@{{ .HostName }}"
|
||||
}
|
||||
|
||||
func (s *Session) init(props properties.Properties, env environment.Environment) {
|
||||
func (s *Session) Init(props properties.Properties, env environment.Environment) {
|
||||
s.props = props
|
||||
s.env = env
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ func TestSessionSegmentTemplate(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
_ = session.enabled()
|
||||
_ = session.Enabled()
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, session), tc.Case)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ const (
|
|||
MappedShellNames properties.Property = "mapped_shell_names"
|
||||
)
|
||||
|
||||
func (s *Shell) template() string {
|
||||
func (s *Shell) Template() string {
|
||||
return "{{ .Name }}"
|
||||
}
|
||||
|
||||
func (s *Shell) enabled() bool {
|
||||
func (s *Shell) Enabled() bool {
|
||||
mappedNames := s.props.GetKeyValueMap(MappedShellNames, make(map[string]string))
|
||||
s.Name = s.env.Shell()
|
||||
for key, val := range mappedNames {
|
||||
|
@ -34,7 +34,7 @@ func (s *Shell) enabled() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (s *Shell) init(props properties.Properties, env environment.Environment) {
|
||||
func (s *Shell) Init(props properties.Properties, env environment.Environment) {
|
||||
s.props = props
|
||||
s.env = env
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ func TestWriteCurrentShell(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
_ = s.enabled()
|
||||
assert.Equal(t, expected, renderTemplate(env, s.template(), s))
|
||||
_ = s.Enabled()
|
||||
assert.Equal(t, expected, renderTemplate(env, s.Template(), s))
|
||||
}
|
||||
|
||||
func TestUseMappedShellNames(t *testing.T) {
|
||||
|
@ -38,8 +38,8 @@ func TestUseMappedShellNames(t *testing.T) {
|
|||
MappedShellNames: map[string]string{"pwsh": "PS"},
|
||||
},
|
||||
}
|
||||
_ = s.enabled()
|
||||
got := renderTemplate(env, s.template(), s)
|
||||
_ = s.Enabled()
|
||||
got := renderTemplate(env, s.Template(), s)
|
||||
assert.Equal(t, tc.Expected, got)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ const (
|
|||
paused = "paused"
|
||||
)
|
||||
|
||||
func (s *Spotify) template() string {
|
||||
func (s *Spotify) Template() string {
|
||||
return "{{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }}"
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ func (s *Spotify) resolveIcon() {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Spotify) init(props properties.Properties, env environment.Environment) {
|
||||
func (s *Spotify) Init(props properties.Properties, env environment.Environment) {
|
||||
s.props = props
|
||||
s.env = env
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
package main
|
||||
|
||||
func (s *Spotify) enabled() bool {
|
||||
func (s *Spotify) Enabled() bool {
|
||||
var err error
|
||||
// Check if running
|
||||
running := s.runAppleScriptCommand("application \"Spotify\" is running")
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestSpotifyDarwinEnabledAndSpotifyPlaying(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
assert.Equal(t, tc.Running == "true", s.enabled())
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, s.template(), s))
|
||||
assert.Equal(t, tc.Running == "true", s.Enabled())
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, s.Template(), s))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ func TestSpotifyStringPlayingSong(t *testing.T) {
|
|||
props: properties.Map{},
|
||||
env: env,
|
||||
}
|
||||
assert.Equal(t, expected, renderTemplate(env, s.template(), s))
|
||||
assert.Equal(t, expected, renderTemplate(env, s.Template(), s))
|
||||
}
|
||||
|
||||
func TestSpotifyStringStoppedSong(t *testing.T) {
|
||||
|
@ -37,5 +37,5 @@ func TestSpotifyStringStoppedSong(t *testing.T) {
|
|||
props: properties.Map{},
|
||||
env: env,
|
||||
}
|
||||
assert.Equal(t, expected, renderTemplate(env, s.template(), s))
|
||||
assert.Equal(t, expected, renderTemplate(env, s.Template(), s))
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func (s *spotify) enabled() bool {
|
||||
func (s *Spotify) Enabled() bool {
|
||||
// search for spotify window to retrieve the title
|
||||
// Can be either "Spotify xxx" or the song name "Candlemass - Spellbreaker"
|
||||
spotifyWindowTitle, err := s.env.WindowTitle("spotify.exe", "^(Spotify.*)|(.*\\s-\\s.*)$")
|
||||
|
|
|
@ -16,10 +16,10 @@ type spotifyArgs struct {
|
|||
runError error
|
||||
}
|
||||
|
||||
func bootStrapSpotifyWindowsTest(args *spotifyArgs) *spotify {
|
||||
func bootStrapSpotifyWindowsTest(args *spotifyArgs) *Spotify {
|
||||
env := new(mock.MockedEnvironment)
|
||||
env.On("WindowTitle", "spotify.exe").Return(args.title, args.runError)
|
||||
s := &spotify{
|
||||
s := &Spotify{
|
||||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ func TestSpotifyWindowsEnabledAndSpotifyNotRunning(t *testing.T) {
|
|||
runError: errors.New(""),
|
||||
}
|
||||
s := bootStrapSpotifyWindowsTest(args)
|
||||
assert.Equal(t, false, s.enabled())
|
||||
assert.Equal(t, false, s.Enabled())
|
||||
}
|
||||
|
||||
func TestSpotifyWindowsEnabledAndSpotifyPlaying(t *testing.T) {
|
||||
|
@ -40,12 +40,12 @@ func TestSpotifyWindowsEnabledAndSpotifyPlaying(t *testing.T) {
|
|||
}
|
||||
env := new(mock.MockedEnvironment)
|
||||
env.On("WindowTitle", "spotify.exe").Return(args.title, args.runError)
|
||||
s := &spotify{
|
||||
s := &Spotify{
|
||||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
assert.Equal(t, true, s.enabled())
|
||||
assert.Equal(t, "\ue602 Candlemass - Spellbreaker", renderTemplate(env, s.template(), s))
|
||||
assert.Equal(t, true, s.Enabled())
|
||||
assert.Equal(t, "\ue602 Candlemass - Spellbreaker", renderTemplate(env, s.Template(), s))
|
||||
}
|
||||
|
||||
func TestSpotifyWindowsEnabledAndSpotifyStopped(t *testing.T) {
|
||||
|
@ -53,5 +53,5 @@ func TestSpotifyWindowsEnabledAndSpotifyStopped(t *testing.T) {
|
|||
title: "Spotify premium",
|
||||
}
|
||||
s := bootStrapSpotifyWindowsTest(args)
|
||||
assert.Equal(t, false, s.enabled())
|
||||
assert.Equal(t, false, s.Enabled())
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func (s *spotify) enabled() bool {
|
||||
func (s *spotify) Enabled() bool {
|
||||
if !s.env.IsWsl() {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ func TestSpotifyWsl(t *testing.T) {
|
|||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedEnabled, s.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, s.template(), s), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedEnabled, s.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, s.Template(), s), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,11 +70,11 @@ func (a *AuthError) Error() string {
|
|||
return a.message
|
||||
}
|
||||
|
||||
func (s *Strava) template() string {
|
||||
func (s *Strava) Template() string {
|
||||
return "{{ if .Error }}{{ .Error }}{{ else }}{{ .Ago }}{{ end }}"
|
||||
}
|
||||
|
||||
func (s *Strava) enabled() bool {
|
||||
func (s *Strava) Enabled() bool {
|
||||
data, err := s.getResult()
|
||||
if err == nil {
|
||||
s.StravaData = *data
|
||||
|
@ -231,7 +231,7 @@ func (s *Strava) getResult() (*StravaData, error) {
|
|||
return data, nil
|
||||
}
|
||||
|
||||
func (s *Strava) init(props properties.Properties, env environment.Environment) {
|
||||
func (s *Strava) Init(props properties.Properties, env environment.Environment) {
|
||||
s.props = props
|
||||
s.env = env
|
||||
}
|
||||
|
|
|
@ -184,14 +184,14 @@ func TestStravaSegment(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
|
||||
enabled := ns.enabled()
|
||||
enabled := ns.Enabled()
|
||||
assert.Equal(t, tc.ExpectedEnabled, enabled, tc.Case)
|
||||
if !enabled {
|
||||
continue
|
||||
}
|
||||
|
||||
if tc.Template == "" {
|
||||
tc.Template = ns.template()
|
||||
tc.Template = ns.Template()
|
||||
}
|
||||
var got = renderTemplate(env, tc.Template, ns)
|
||||
|
||||
|
|
|
@ -35,18 +35,18 @@ const (
|
|||
Precision properties.Property = "precision"
|
||||
)
|
||||
|
||||
func (s *SystemInfo) template() string {
|
||||
func (s *SystemInfo) Template() string {
|
||||
return "{{ round .PhysicalPercentUsed .Precision }}"
|
||||
}
|
||||
|
||||
func (s *SystemInfo) enabled() bool {
|
||||
func (s *SystemInfo) Enabled() bool {
|
||||
if s.PhysicalPercentUsed == 0 && s.SwapPercentUsed == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *SystemInfo) init(props properties.Properties, env environment.Environment) {
|
||||
func (s *SystemInfo) Init(props properties.Properties, env environment.Environment) {
|
||||
s.props = props
|
||||
s.env = env
|
||||
s.Precision = s.props.GetInt(Precision, 2)
|
||||
|
|
|
@ -56,7 +56,7 @@ func TestSysInfo(t *testing.T) {
|
|||
tc.SysInfo.props = properties.Map{
|
||||
Precision: tc.Precision,
|
||||
}
|
||||
enabled := tc.SysInfo.enabled()
|
||||
enabled := tc.SysInfo.Enabled()
|
||||
if tc.ExpectDisabled {
|
||||
assert.Equal(t, false, enabled, tc.Case)
|
||||
} else {
|
||||
|
|
|
@ -12,16 +12,16 @@ type Terraform struct {
|
|||
WorkspaceName string
|
||||
}
|
||||
|
||||
func (tf *Terraform) template() string {
|
||||
func (tf *Terraform) Template() string {
|
||||
return "{{ .WorkspaceName }}"
|
||||
}
|
||||
|
||||
func (tf *Terraform) init(props properties.Properties, env environment.Environment) {
|
||||
func (tf *Terraform) Init(props properties.Properties, env environment.Environment) {
|
||||
tf.props = props
|
||||
tf.env = env
|
||||
}
|
||||
|
||||
func (tf *Terraform) enabled() bool {
|
||||
func (tf *Terraform) Enabled() bool {
|
||||
cmd := "terraform"
|
||||
if !tf.env.HasCommand(cmd) || !tf.env.HasFolder(tf.env.Pwd()+"/.terraform") {
|
||||
return false
|
||||
|
|
|
@ -33,7 +33,7 @@ func TestTerraformWriterDisabled(t *testing.T) {
|
|||
hasTfFolder: false,
|
||||
}
|
||||
terraform := bootStrapTerraformTest(args)
|
||||
assert.False(t, terraform.enabled())
|
||||
assert.False(t, terraform.Enabled())
|
||||
}
|
||||
|
||||
func TestTerraformMissingDir(t *testing.T) {
|
||||
|
@ -42,7 +42,7 @@ func TestTerraformMissingDir(t *testing.T) {
|
|||
hasTfFolder: false,
|
||||
}
|
||||
terraform := bootStrapTerraformTest(args)
|
||||
assert.False(t, terraform.enabled())
|
||||
assert.False(t, terraform.Enabled())
|
||||
}
|
||||
|
||||
func TestTerraformMissingBinary(t *testing.T) {
|
||||
|
@ -51,7 +51,7 @@ func TestTerraformMissingBinary(t *testing.T) {
|
|||
hasTfFolder: true,
|
||||
}
|
||||
terraform := bootStrapTerraformTest(args)
|
||||
assert.False(t, terraform.enabled())
|
||||
assert.False(t, terraform.Enabled())
|
||||
}
|
||||
|
||||
func TestTerraformEnabled(t *testing.T) {
|
||||
|
@ -62,5 +62,5 @@ func TestTerraformEnabled(t *testing.T) {
|
|||
workspaceName: expected,
|
||||
}
|
||||
terraform := bootStrapTerraformTest(args)
|
||||
assert.True(t, terraform.enabled())
|
||||
assert.True(t, terraform.Enabled())
|
||||
}
|
||||
|
|
|
@ -12,15 +12,15 @@ type Text struct {
|
|||
Text string
|
||||
}
|
||||
|
||||
func (t *Text) template() string {
|
||||
func (t *Text) Template() string {
|
||||
return "{{ .Text }}"
|
||||
}
|
||||
|
||||
func (t *Text) enabled() bool {
|
||||
func (t *Text) Enabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (t *Text) init(props properties.Properties, env environment.Environment) {
|
||||
func (t *Text) Init(props properties.Properties, env environment.Environment) {
|
||||
t.props = props
|
||||
t.env = env
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ const (
|
|||
TimeFormat properties.Property = "time_format"
|
||||
)
|
||||
|
||||
func (t *Time) template() string {
|
||||
func (t *Time) Template() string {
|
||||
return "{{ .CurrentDate | date \"" + t.props.GetString(TimeFormat, "15:04:05") + "\" }}"
|
||||
}
|
||||
|
||||
func (t *Time) enabled() bool {
|
||||
func (t *Time) Enabled() bool {
|
||||
// if no date set, use now(unit testing)
|
||||
if t.CurrentDate.IsZero() {
|
||||
t.CurrentDate = time.Now()
|
||||
|
@ -30,7 +30,7 @@ func (t *Time) enabled() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (t *Time) init(props properties.Properties, env environment.Environment) {
|
||||
func (t *Time) Init(props properties.Properties, env environment.Environment) {
|
||||
t.props = props
|
||||
t.env = env
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ func TestTimeSegmentTemplate(t *testing.T) {
|
|||
props: properties.Map{},
|
||||
CurrentDate: currentDate,
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedEnabled, tempus.enabled())
|
||||
assert.Equal(t, tc.ExpectedEnabled, tempus.Enabled())
|
||||
if tc.Template == "" {
|
||||
tc.Template = tempus.template()
|
||||
tc.Template = tempus.Template()
|
||||
}
|
||||
if tc.ExpectedEnabled {
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, tempus), tc.Case)
|
||||
|
|
|
@ -24,11 +24,11 @@ type wtData struct {
|
|||
End string `json:"end"`
|
||||
}
|
||||
|
||||
func (w *Wakatime) template() string {
|
||||
func (w *Wakatime) Template() string {
|
||||
return "{{ secondsRound .CummulativeTotal.Seconds }}"
|
||||
}
|
||||
|
||||
func (w *Wakatime) enabled() bool {
|
||||
func (w *Wakatime) Enabled() bool {
|
||||
err := w.setAPIData()
|
||||
return err == nil
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func (w *Wakatime) setAPIData() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (w *Wakatime) init(props properties.Properties, env environment.Environment) {
|
||||
func (w *Wakatime) Init(props properties.Properties, env environment.Environment) {
|
||||
w.props = props
|
||||
w.env = env
|
||||
}
|
||||
|
|
|
@ -90,6 +90,6 @@ func TestWTTrackedTime(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.ErrorIs(t, tc.Error, w.setAPIData(), tc.Case+" - Error")
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, w.template(), w), tc.Case+" - String")
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, w.Template(), w), tc.Case+" - String")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ const (
|
|||
defaultTemplate = "{{ if .Error }}{{ .Error }}{{ else }}\uFAA8 {{ .SSID }} {{ .Signal }}% {{ .ReceiveRate }}Mbps{{ end }}"
|
||||
)
|
||||
|
||||
func (w *Wifi) template() string {
|
||||
func (w *Wifi) Template() string {
|
||||
return defaultTemplate
|
||||
}
|
||||
|
||||
func (w *Wifi) enabled() bool {
|
||||
func (w *Wifi) Enabled() bool {
|
||||
// This segment only supports Windows/WSL for now
|
||||
if w.env.Platform() != environment.WindowsPlatform && !w.env.IsWsl() {
|
||||
return false
|
||||
|
@ -40,7 +40,7 @@ func (w *Wifi) enabled() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (w *Wifi) init(props properties.Properties, env environment.Environment) {
|
||||
func (w *Wifi) Init(props properties.Properties, env environment.Environment) {
|
||||
w.props = props
|
||||
w.env = env
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ func TestWiFiSegment(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.ExpectedEnabled, w.enabled(), tc.Case)
|
||||
assert.Equal(t, tc.ExpectedEnabled, w.Enabled(), tc.Case)
|
||||
if tc.Network != nil || tc.DisplayError {
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, "{{ if .Error }}{{ .Error }}{{ else }}{{ .SSID }}{{ end }}", w), tc.Case)
|
||||
}
|
||||
|
|
|
@ -21,16 +21,16 @@ const (
|
|||
Fallback properties.Property = "fallback"
|
||||
)
|
||||
|
||||
func (wr *WindowsRegistry) template() string {
|
||||
func (wr *WindowsRegistry) Template() string {
|
||||
return "{{ .Value }}"
|
||||
}
|
||||
|
||||
func (wr *WindowsRegistry) init(props properties.Properties, env environment.Environment) {
|
||||
func (wr *WindowsRegistry) Init(props properties.Properties, env environment.Environment) {
|
||||
wr.props = props
|
||||
wr.env = env
|
||||
}
|
||||
|
||||
func (wr *WindowsRegistry) enabled() bool {
|
||||
func (wr *WindowsRegistry) Enabled() bool {
|
||||
if wr.env.GOOS() != environment.WindowsPlatform {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ func TestWinReg(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.ExpectedSuccess, r.enabled(), tc.CaseDescription)
|
||||
assert.Equal(t, tc.ExpectedValue, renderTemplate(env, r.template(), r), tc.CaseDescription)
|
||||
assert.Equal(t, tc.ExpectedSuccess, r.Enabled(), tc.CaseDescription)
|
||||
assert.Equal(t, tc.ExpectedValue, renderTemplate(env, r.Template(), r), tc.CaseDescription)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,18 +18,18 @@ const (
|
|||
APIURL properties.Property = "api_url"
|
||||
)
|
||||
|
||||
func (y *Ytm) template() string {
|
||||
func (y *Ytm) Template() string {
|
||||
return "{{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }}"
|
||||
}
|
||||
|
||||
func (y *Ytm) enabled() bool {
|
||||
func (y *Ytm) Enabled() bool {
|
||||
err := y.setStatus()
|
||||
// If we don't get a response back (error), the user isn't running
|
||||
// YTMDA, or they don't have the RC API enabled.
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (y *Ytm) init(props properties.Properties, env environment.Environment) {
|
||||
func (y *Ytm) Init(props properties.Properties, env environment.Environment) {
|
||||
y.props = props
|
||||
y.env = env
|
||||
}
|
||||
|
|
|
@ -55,6 +55,6 @@ func TestYTMDAStopped(t *testing.T) {
|
|||
func TestYTMDAError(t *testing.T) {
|
||||
json := `{ "player": { "hasSong": false }, "track": { "author": "", "title": "" } }`
|
||||
ytm := bootstrapYTMDATest(json, errors.New("Oh noes"))
|
||||
enabled := ytm.enabled()
|
||||
enabled := ytm.Enabled()
|
||||
assert.False(t, enabled)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue