Skip to content

Commit

Permalink
feat(project): add support for dart
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksbabieiev authored and JanDeDobbeleer committed Nov 4, 2024
1 parent fbcd78e commit 17c19c3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/segments/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/regex"
"golang.org/x/exp/slices"

yaml "github.com/goccy/go-yaml"
toml "github.com/pelletier/go-toml/v2"
)

Expand Down Expand Up @@ -80,6 +81,11 @@ func (n *Project) Enabled() bool {
Files: []string{"composer.json"},
Fetcher: n.getNodePackage,
},
{
Name: "dart",
Files: []string{"pubspec.yaml"},
Fetcher: n.getDartPackage,
},
{
Name: "nuspec",
Files: []string{"*.nuspec"},
Expand Down Expand Up @@ -180,6 +186,18 @@ func (n *Project) getPythonPackage(item ProjectItem) *ProjectData {
}
}

func (n *Project) getDartPackage(item ProjectItem) *ProjectData {
content := n.env.FileContent(item.Files[0])
var data ProjectData
err := yaml.Unmarshal([]byte(content), &data)
if err != nil {
n.Error = err.Error()
return nil
}

return &data
}

func (n *Project) getNuSpecPackage(_ ProjectItem) *ProjectData {
files := n.env.LsDir(n.env.Pwd())
var content string
Expand Down
46 changes: 46 additions & 0 deletions src/segments/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ func TestPackage(t *testing.T) {
Name: "node", File: "package.json",
PackageContents: "{\"version\":\"3.2.1\",\"name\":\"test\"}",
},
{
Case: "1.0.0 dart",
ExpectedEnabled: true,
ExpectedString: "\uf487 1.0.0 test",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "name: test\nversion: 1.0.0",
},
{
Case: "3.2.1 dart",
ExpectedEnabled: true,
ExpectedString: "\uf487 3.2.1 test",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "name: test\nversion: 3.2.1",
},
{
Case: "1.0.0 cargo",
ExpectedEnabled: true,
Expand Down Expand Up @@ -130,6 +146,14 @@ func TestPackage(t *testing.T) {
File: "package.json",
PackageContents: "{\"name\":\"test\"}",
},
{
Case: "No version present dart",
ExpectedEnabled: true,
ExpectedString: "test",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "name: test",
},
{
Case: "No version present cargo",
ExpectedEnabled: true,
Expand Down Expand Up @@ -162,6 +186,14 @@ func TestPackage(t *testing.T) {
File: "package.json",
PackageContents: "{\"version\":\"1.0.0\"}",
},
{
Case: "No name present dart",
ExpectedEnabled: true,
ExpectedString: "\uf487 1.0.0",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "version: 1.0.0",
},
{
Case: "No name present cargo",
ExpectedEnabled: true,
Expand Down Expand Up @@ -193,6 +225,13 @@ func TestPackage(t *testing.T) {
File: "package.json",
PackageContents: "{}",
},
{
Case: "Empty project package dart",
ExpectedEnabled: true,
Name: "dart",
File: "pubspec.yaml",
PackageContents: "",
},
{
Case: "Empty project package cargo",
ExpectedEnabled: true,
Expand Down Expand Up @@ -221,6 +260,13 @@ func TestPackage(t *testing.T) {
File: "Cargo.toml",
PackageContents: "[",
},
{
Case: "Invalid yaml",
ExpectedString: "[1:1] sequence was used where mapping is expected\n> 1 | [\n ^",
Name: "dart",
File: "pubspec.yaml",
PackageContents: "[",
},
{
Case: "Julia project",
ExpectedEnabled: true,
Expand Down
3 changes: 2 additions & 1 deletion website/docs/segments/system/project.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Supports:
- Cargo project (`Cargo.toml`)
- Python project (`pyproject.toml`, supports metadata defined according to [PEP 621][pep621-standard] or [Poetry][poetry-standard])
- PHP project (`composer.json`)
- Dart project (`pubspec.yaml`)
- Any nuspec based project (`*.nuspec`, first file match info is displayed)
- .NET project (`*.sln`, `*.slnf`, `*.csproj`, `*.vbproj` or `*.fsproj`, first file match info is displayed)
- Julia project (`JuliaProject.toml`, `Project.toml`)
Expand Down Expand Up @@ -55,7 +56,7 @@ import Config from "@site/src/components/Config.js";

| Name | Type | Description |
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `.Type` | `string` | The type of project:<ul><li>`node`</li><li>`cargo`</li><li>`python`</li><li>`php`</li><li>`nuspec`</li><li>`dotnet`</li><li>`julia`</li><li>`powershell`</li></ul> |
| `.Type` | `string` | The type of project:<ul><li>`node`</li><li>`cargo`</li><li>`python`</li><li>`php`</li><li>`dart`</li><li>`nuspec`</li><li>`dotnet`</li><li>`julia`</li><li>`powershell`</li></ul> |
| `.Version` | `string` | The version of your project |
| `.Target` | `string` | The target framwork/language version of your project |
| `.Name` | `string` | The name of your project |
Expand Down

0 comments on commit 17c19c3

Please sign in to comment.