diff --git a/docs/docs/segment-angular.md b/docs/docs/segment-angular.md new file mode 100644 index 00000000..6e2a1f86 --- /dev/null +++ b/docs/docs/segment-angular.md @@ -0,0 +1,31 @@ +--- +id: angular +title: Angular +sidebar_label: Angular +--- + +## What + +Display the currently active Angular CLI version. + +## Sample Configuration + +```json +{ + "type": "angular", + "style": "powerline", + "powerline_symbol": "", + "foreground": "#000000", + "background": "#1976d2", + "properties": { + "prefix": "\uE753" + } +} +``` + +## Properties + +- display_version: `boolean` - display the active version or not; useful if all you need is an icon indicating `ng` +- display_mode: `string` - determines when the segment is displayed + - `always`: the segment is always displayed + - `files`: the segment is only displayed when `angular.json` file is present (default) diff --git a/docs/sidebars.js b/docs/sidebars.js index da432112..578ae258 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -24,6 +24,7 @@ module.exports = { type: "category", label: "Segments", items: [ + "angular", "aws", "az", "azfunc", diff --git a/src/segment.go b/src/segment.go index 020c680d..90a30977 100644 --- a/src/segment.go +++ b/src/segment.go @@ -126,6 +126,8 @@ const ( OWM SegmentType = "owm" // Memory writes used memory percentage Memory SegmentType = "memory" + // Angular writes which angular cli version us currently active + Angular SegmentType = "angular" ) func (segment *Segment) string() string { @@ -279,6 +281,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error { Nbgv: &nbgv{}, Rust: &rust{}, Memory: &memory{}, + Angular: &angular{}, } if writer, ok := functions[segment.Type]; ok { props := &properties{ diff --git a/src/segment_angular.go b/src/segment_angular.go new file mode 100644 index 00000000..fd242ce8 --- /dev/null +++ b/src/segment_angular.go @@ -0,0 +1,29 @@ +package main + +type angular struct { + language *language +} + +func (a *angular) string() string { + return a.language.string() +} + +func (a *angular) init(props *properties, env environmentInfo) { + a.language = &language{ + env: env, + props: props, + extensions: []string{"angular.json"}, + commands: []*cmd{ + { + executable: "ng", + args: []string{"--version"}, + regex: `Angular CLI: (?:(?P((?P[0-9]+).(?P[0-9]+).(?P[0-9]+))))`, + }, + }, + versionURLTemplate: "[%s](https://github.com/angular/angular/releases/tag/%s.%s.%s)", + } +} + +func (a *angular) enabled() bool { + return a.language.enabled() +} diff --git a/src/segment_angular_test.go b/src/segment_angular_test.go new file mode 100644 index 00000000..bf7d0e15 --- /dev/null +++ b/src/segment_angular_test.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAngularCliVersionDisplayed(t *testing.T) { + cases := []struct { + Case string + ExpectedString string + Version string + }{ + {Case: "Angular 12.2.9", ExpectedString: "12.2.9", Version: "Angular CLI: 12.2.9"}, + } + + for _, ta := range cases { + params := &mockedLanguageParams{ + cmd: "ng", + versionParam: "--version", + versionOutput: ta.Version, + extension: "angular.json", + } + + env, props := getMockedLanguageEnv(params) + angular := &angular{} + angular.init(props, env) + assert.True(t, angular.enabled(), fmt.Sprintf("Failed in case: %s", ta.Case)) + assert.Equal(t, ta.ExpectedString, angular.string(), fmt.Sprintf("Failed in case: %s", ta.Case)) + } +} diff --git a/themes/schema.json b/themes/schema.json index 560c0b8c..7b92ec47 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -169,7 +169,8 @@ "dart", "rust", "owm", - "memory" + "memory", + "angularcli" ] }, "style": { @@ -1712,6 +1713,29 @@ } } } + }, + { + "if": { + "properties": { + "type": { "const": "angularcli" } + } + }, + "then": { + "title": "Angular CLI Segment", + "description": "https://ohmyposh.dev/docs/angularcli", + "properties": { + "properties": { + "properties": { + "display_version": { + "$ref": "#/definitions/display_version" + }, + "display_mode": { + "$ref": "#/definitions/display_mode" + } + } + } + } + } } ] }