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