mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 03:49:40 -08:00
feat: angular cli segment
This commit is contained in:
parent
5db8f0fbe5
commit
f08c283105
31
docs/docs/segment-angular.md
Normal file
31
docs/docs/segment-angular.md
Normal 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)
|
|
@ -24,6 +24,7 @@ module.exports = {
|
||||||
type: "category",
|
type: "category",
|
||||||
label: "Segments",
|
label: "Segments",
|
||||||
items: [
|
items: [
|
||||||
|
"angular",
|
||||||
"aws",
|
"aws",
|
||||||
"az",
|
"az",
|
||||||
"azfunc",
|
"azfunc",
|
||||||
|
|
|
@ -126,6 +126,8 @@ const (
|
||||||
OWM SegmentType = "owm"
|
OWM SegmentType = "owm"
|
||||||
// Memory writes used memory percentage
|
// Memory writes used memory percentage
|
||||||
Memory SegmentType = "memory"
|
Memory SegmentType = "memory"
|
||||||
|
// Angular writes which angular cli version us currently active
|
||||||
|
Angular SegmentType = "angular"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (segment *Segment) string() string {
|
func (segment *Segment) string() string {
|
||||||
|
@ -279,6 +281,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
|
||||||
Nbgv: &nbgv{},
|
Nbgv: &nbgv{},
|
||||||
Rust: &rust{},
|
Rust: &rust{},
|
||||||
Memory: &memory{},
|
Memory: &memory{},
|
||||||
|
Angular: &angular{},
|
||||||
}
|
}
|
||||||
if writer, ok := functions[segment.Type]; ok {
|
if writer, ok := functions[segment.Type]; ok {
|
||||||
props := &properties{
|
props := &properties{
|
||||||
|
|
29
src/segment_angular.go
Normal file
29
src/segment_angular.go
Normal 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()
|
||||||
|
}
|
33
src/segment_angular_test.go
Normal file
33
src/segment_angular_test.go
Normal 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))
|
||||||
|
}
|
||||||
|
}
|
|
@ -169,7 +169,8 @@
|
||||||
"dart",
|
"dart",
|
||||||
"rust",
|
"rust",
|
||||||
"owm",
|
"owm",
|
||||||
"memory"
|
"memory",
|
||||||
|
"angularcli"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"style": {
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue