Skip to content

Commit

Permalink
Improve detection logic a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
markelog committed Jul 29, 2018
1 parent 4977f8d commit 1384604
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bin/ec/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ var _ = Describe("main logic", func() {
result, _ := Command("node", "-v").CombinedOutput()

actual := string(result)
expected := `v5.12.0`
expected := "v5.12.0"

Expect(actual).To(ContainSubstring(expected))

Expand Down
9 changes: 6 additions & 3 deletions cmd/commands/ls/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/markelog/eclectica/io"
"github.com/markelog/eclectica/list"
"github.com/markelog/eclectica/plugins"
"github.com/markelog/eclectica/versions"
)

// Is action remote?
Expand Down Expand Up @@ -62,11 +63,13 @@ func run(cmd *cobra.Command, args []string) {
}

// List versions
func listVersions(versions []string, current string) {
func listVersions(vers []string, current string) {
completeCurrent, _ := versions.Complete(current, vers)

fmt.Println()
for i, version := range versions {
for i, version := range vers {

if current == version {
if completeCurrent == version {
print.CurrentVersion(version)
continue
}
Expand Down
5 changes: 2 additions & 3 deletions io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (
"regexp"

"github.com/go-errors/errors"
"github.com/markelog/eclectica/versions"
)

const (
perm = 0700
)

var (
versionPattern = `\d+(\.\d+)?(\.\d+)?`
versionPattern = `(\d+(\.\d+)?(\.\d+)?)|(latest)`
rVersion = regexp.MustCompile(versionPattern)
)

Expand Down Expand Up @@ -59,7 +58,7 @@ func ExtractVersion(file string) (string, error) {

version := match[0][0]

return versions.Semverify(version), nil
return version, nil
}

// GetVersion finds a file by provided argument and extracts
Expand Down
21 changes: 7 additions & 14 deletions io/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ var _ = Describe("io", func() {
Expect(result).To(Equal("1.2.3"))
})

It("gets version with 1.2 format", func() {
result, err := ExtractVersion("1.2")

Expect(err).To(BeNil())
Expect(result).To(Equal("1.2.0"))
})

It("gets version with one digit format", func() {
result, err := ExtractVersion("1")

Expect(err).To(BeNil())
Expect(result).To(Equal("1.0.0"))
})

It("returns an error if there is no version", func() {
result, err := ExtractVersion("test")

Expand All @@ -54,6 +40,13 @@ var _ = Describe("io", func() {
Expect(err).To(BeNil())
Expect(result).To(Equal("8.11.2"))
})

It("gets version with \"latest\" keyword", func() {
result, err := ExtractVersion("latest")

Expect(err).To(BeNil())
Expect(result).To(Equal("latest"))
})
})

Describe("FindDotFile", func() {
Expand Down

0 comments on commit 1384604

Please sign in to comment.