Skip to content

Commit

Permalink
feat: angular cli segment
Browse files Browse the repository at this point in the history
  • Loading branch information
tjackadams authored and JanDeDobbeleer committed Oct 17, 2021
1 parent 5db8f0f commit f08c283
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 1 deletion.
31 changes: 31 additions & 0 deletions 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)
1 change: 1 addition & 0 deletions docs/sidebars.js
Expand Up @@ -24,6 +24,7 @@ module.exports = {
type: "category",
label: "Segments",
items: [
"angular",
"aws",
"az",
"azfunc",
Expand Down
3 changes: 3 additions & 0 deletions src/segment.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down
29 changes: 29 additions & 0 deletions 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<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 changes: 33 additions & 0 deletions 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))
}
}
26 changes: 25 additions & 1 deletion themes/schema.json
Expand Up @@ -169,7 +169,8 @@
"dart",
"rust",
"owm",
"memory"
"memory",
"angularcli"
]
},
"style": {
Expand Down Expand Up @@ -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"
}
}
}
}
}
}
]
}
Expand Down

0 comments on commit f08c283

Please sign in to comment.