-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(segment): add bazel segment type
- Loading branch information
Showing
6 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package segments | ||
|
||
import ( | ||
"github.com/jandedobbeleer/oh-my-posh/src/platform" | ||
"github.com/jandedobbeleer/oh-my-posh/src/properties" | ||
) | ||
|
||
type Bazel struct { | ||
language | ||
|
||
Icon string | ||
} | ||
|
||
const ( | ||
// Bazel's icon | ||
Icon properties.Property = "icon" | ||
) | ||
|
||
func (c *Bazel) Template() string { | ||
return " {{ if .Error }}{{ .Icon }} {{ .Error }}{{ else }}{{ url .Icon .URL }} {{ .Full }}{{ end }} " | ||
} | ||
|
||
func (c *Bazel) Init(props properties.Properties, env platform.Environment) { | ||
c.language = language{ | ||
env: env, | ||
props: props, | ||
extensions: []string{"*.bazel", "*.bzl", "BUILD", "WORKSPACE", ".bazelrc", ".bazelversion"}, | ||
folders: []string{"bazel-bin", "bazel-out", "bazel-testlogs"}, | ||
commands: []*cmd{ | ||
{ | ||
executable: "bazel", | ||
args: []string{"--version"}, | ||
regex: `bazel (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`, | ||
}, | ||
}, | ||
// Use the correct URL for Bazel 6.x. it does not have the docs subdomain. | ||
versionURLTemplate: "https://{{ if ne .Major \"6\" }}docs.{{ end }}bazel.build/versions/{{ .Major }}.{{ .Minor }}.{{ .Patch }}", | ||
} | ||
c.Icon = props.GetString(Icon, "\ue63a") | ||
} | ||
|
||
func (c *Bazel) Enabled() bool { | ||
return c.language.Enabled() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package segments | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBazel(t *testing.T) { | ||
cases := []struct { | ||
Case string | ||
ExpectedString string | ||
Version string | ||
}{ | ||
{Case: "bazel 6.4.0", ExpectedString: "6.4.0", Version: "bazel 6.4.0"}, | ||
{Case: "bazel 10.11.12", ExpectedString: "10.11.12", Version: "bazel 10.11.12"}, | ||
{Case: "bazel error", ExpectedString: "err parsing info from bazel with", Version: ""}, | ||
{Case: "", ExpectedString: "err parsing info from bazel with", Version: ""}, | ||
} | ||
for _, tc := range cases { | ||
params := &mockedLanguageParams{ | ||
cmd: "bazel", | ||
versionParam: "--version", | ||
versionOutput: tc.Version, | ||
extension: "*.bazel", | ||
} | ||
env, props := getMockedLanguageEnv(params) | ||
b := &Bazel{} | ||
b.Init(props, env) | ||
failMsg := fmt.Sprintf("Failed in case: %s", tc.Case) | ||
assert.True(t, b.Enabled(), failMsg) | ||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, b.Template(), b), failMsg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
id: bazel | ||
title: Bazel | ||
sidebar_label: Bazel | ||
--- | ||
|
||
## What | ||
|
||
Display the currently active [Bazel][bazel-github] version. | ||
|
||
## Sample Configuration | ||
|
||
import Config from "@site/src/components/Config.js"; | ||
|
||
<Config data={{ | ||
"type": "bazel", | ||
"style": "powerline", | ||
"powerline_symbol": "\uE0B0", | ||
"foreground": "#ffffff", | ||
"background": "#43a047", | ||
}}/> | ||
|
||
## Properties | ||
|
||
| Name | Type | Description | | ||
| ---------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `home_enabled` | `boolean` | display the segment in the HOME folder or not - defaults to `false` | | ||
| `fetch_version` | `boolean` | display the Bazel version - defaults to `true` | | ||
| `missing_command_text` | `string` | text to display when the command is missing - defaults to empty | | ||
| `display_mode` | `string` | <ul><li>`always`: the segment is always displayed</li><li>`files`: the segment is only displayed when `*.bazel`, `*.bzl`, `.bazelrc`, `.bazelversion`, `BUILD` or `WORKSPACE` files or any of Bazel's output folders are present (**default**)</li></ul> | | ||
| `version_url_template` | `string` | a go [text/template][go-text-template] [template][templates] that creates the URL of the version info documentation | | ||
| `icon` | `string` | the icon for the segment - defaults to `"\ue63a"` | | ||
|
||
## Template ([info][templates]) | ||
|
||
:::note default template | ||
|
||
```template | ||
{{ if .Error }}{{ .Icon }} {{ .Error }}{{ else }}{{ url .Icon .URL }} {{ .Full }}{{ end }} | ||
``` | ||
|
||
::: | ||
|
||
### Properties | ||
|
||
| Name | Type | Description | | ||
| -------- | -------- | -------------------------------------------------- | | ||
| `.Full` | `string` | the full version | | ||
| `.Major` | `string` | major number | | ||
| `.Minor` | `string` | minor number | | ||
| `.Patch` | `string` | patch number | | ||
| `.URL` | `string` | URL of the version info / release notes | | ||
| `.Error` | `string` | error encountered when fetching the version string | | ||
| `.Icon` | `string` | the icon representing Bazel's logo | | ||
|
||
[bazel-github]: https://github.com/bazelbuild/bazel | ||
[go-text-template]: https://golang.org/pkg/text/template/ | ||
[templates]: /docs/configuration/templates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters