feat: angular cli segment

This commit is contained in:
Thomas Adams 2021-10-13 08:05:29 +01:00 committed by Jan De Dobbeleer
parent 5db8f0fbe5
commit f08c283105
6 changed files with 122 additions and 1 deletions

View file

@ -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)

View file

@ -24,6 +24,7 @@ module.exports = {
type: "category",
label: "Segments",
items: [
"angular",
"aws",
"az",
"azfunc",

View file

@ -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{

29
src/segment_angular.go Normal file
View file

@ -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<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
},
},
versionURLTemplate: "[%s](https://github.com/angular/angular/releases/tag/%s.%s.%s)",
}
}
func (a *angular) enabled() bool {
return a.language.enabled()
}

View file

@ -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))
}
}

View file

@ -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"
}
}
}
}
}
}
]
}