Skip to content

Commit

Permalink
feat: nbgv segment
Browse files Browse the repository at this point in the history
resolves #777
  • Loading branch information
JanDeDobbeleer committed Jun 4, 2021
1 parent 683a8ec commit 3d05f2d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ const (
Crystal SegmentType = "crystal"
// Dart writes the active dart version
Dart SegmentType = "dart"
// Nbgv writes the nbgv version information
Nbgv SegmentType = "nbgv"
)

func (segment *Segment) string() string {
Expand Down Expand Up @@ -245,6 +247,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
AZFunc: &azfunc{},
Crystal: &crystal{},
Dart: &dart{},
Nbgv: &nbgv{},
}
if writer, ok := functions[segment.Type]; ok {
props := &properties{
Expand Down
41 changes: 41 additions & 0 deletions src/segment_nbgv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

type nbgv struct {
props *properties
env environmentInfo
Nbgv *VersionInfo
}

type VersionInfo struct {
VersionFileFound bool `json:"VersionFileFound"`
Version bool `json:"Version"`
AssemblyVersion bool `json:"AssemblyVersion"`
AssemblyInformationalVersion bool `json:"AssemblyInformationalVersion"`
NuGetPackageVersion bool `json:"NuGetPackageVersion"`
ChocolateyPackageVersion bool `json:"ChocolateyPackageVersion"`
NpmPackageVersion bool `json:"NpmPackageVersion"`
SimpleVersion bool `json:"SimpleVersion"`
}

func (n *nbgv) enabled() bool {
return true
}

func (n *nbgv) string() string {
segmentTemplate := n.props.getString(SegmentTemplate, "{{ .Nbgv.Version }}")
template := &textTemplate{
Template: segmentTemplate,
Context: n,
Env: n.env,
}
text, err := template.render()
if err != nil {
return err.Error()
}
return text
}

func (n *nbgv) init(props *properties, env environmentInfo) {
n.props = props
n.env = env
}

0 comments on commit 3d05f2d

Please sign in to comment.