Skip to content

Commit

Permalink
refactor: hide erorr for languages
Browse files Browse the repository at this point in the history
resolves #400
  • Loading branch information
JanDeDobbeleer committed Feb 14, 2021
1 parent 375184c commit 9457be3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/docs/segment-dotnet.md
Expand Up @@ -27,6 +27,7 @@ Display the currently active .NET SDK version.

- display_version: `boolean` - display the active version or not; useful if all you need is an icon indicating `dotnet`
is present - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: the segment is always displayed
Expand Down
1 change: 1 addition & 0 deletions docs/docs/segment-golang.md
Expand Up @@ -26,6 +26,7 @@ Display the currently active golang version.
## Properties

- display_version: `boolean` - display the golang version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: the segment is always displayed
Expand Down
1 change: 1 addition & 0 deletions docs/docs/segment-julia.md
Expand Up @@ -26,6 +26,7 @@ Display the currently active julia version.
## Properties

- display_version: `boolean` - display the julia version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: the segment is always displayed
Expand Down
1 change: 1 addition & 0 deletions docs/docs/segment-node.md
Expand Up @@ -26,6 +26,7 @@ Display the currently active node version.
## Properties

- display_version: `boolean` - display the node version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: The segment is always displayed
Expand Down
1 change: 1 addition & 0 deletions docs/docs/segment-python.md
Expand Up @@ -30,6 +30,7 @@ Supports conda, virtualenv and pyenv.
- display_default_env: `boolean` - show the name of the virtualenv when it's default (`system`, `base`)
or not - defaults to `true`
- display_version: `boolean` - display the python version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: the segment is always displayed
Expand Down
1 change: 1 addition & 0 deletions docs/docs/segment-ruby.md
Expand Up @@ -26,6 +26,7 @@ Display the currently active ruby version.
## Properties

- display_version: `boolean` - display the ruby version - defaults to `true`
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
- missing_command_text: `string` - text to display when the command is missing - defaults to empty
- display_mode: `string` - determines when the segment is displayed
- `always`: the segment is always displayed
Expand Down
6 changes: 5 additions & 1 deletion src/segment_language.go
Expand Up @@ -98,9 +98,13 @@ func (l *language) string() string {
}

err := l.setVersion()
if err != nil {
displayError := l.props.getBool(DisplayError, true)
if err != nil && displayError {
return err.Error()
}
if err != nil {
return ""
}

if l.props.getBool(EnableHyperlink, false) {
return l.activeCommand.buildVersionURL(l.versionURLTemplate)
Expand Down
18 changes: 18 additions & 0 deletions src/segment_language_test.go
Expand Up @@ -261,6 +261,24 @@ func TestLanguageEnabledMissingCommandCustomText(t *testing.T) {
assert.Equal(t, expected, lang.string(), "unicorn is available and uni and corn files are found")
}

func TestLanguageEnabledMissingCommandCustomTextHideError(t *testing.T) {
props := map[Property]interface{}{
MissingCommandText: "missing",
DisplayError: false,
}
args := &languageArgs{
commands: []*cmd{},
extensions: []string{uni, corn},
enabledExtensions: []string{uni, corn},
enabledCommands: []string{"unicorn"},
version: universion,
properties: props,
}
lang := bootStrapLanguageTest(args)
assert.True(t, lang.enabled())
assert.Equal(t, "", lang.string())
}

func TestLanguageEnabledCommandExitCode(t *testing.T) {
expected := 200
args := &languageArgs{
Expand Down

0 comments on commit 9457be3

Please sign in to comment.