Skip to content

Commit

Permalink
Merge pull request #13 from befovy/develop
Browse files Browse the repository at this point in the history
fix: version name with no v prefix, fixes #12
  • Loading branch information
befovy authored Jun 25, 2020
2 parents be289d3 + dfaf0ea commit 8b90a26
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 19 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ jobs:
dep ensure
fi
- name: Build
- name: Build for Linux
run: go build -v .

- name: Build for Mac OS
run: env GOOS=darwin GOARCH=amd64 go build -v .

- name: Build for Windows
run: env GOOS=windows GOARCH=amd64 go build -v .

- name: Test
run: go test -v github.com/befovy/fvm/...
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea/
fvm.iml
.DS_Store
.DS_Store

# binary
fvm
3 changes: 2 additions & 1 deletion cmd/current.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package cmd

import (
"errors"
"github.com/befovy/fvm/fvmgo"
"os"

"github.com/befovy/fvm/fvmgo"

"github.com/spf13/cobra"
)

Expand Down
5 changes: 3 additions & 2 deletions cmd/flutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ limitations under the License.
package cmd

import (
"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
"os"
"path/filepath"

"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
)

func init() {
Expand Down
5 changes: 3 additions & 2 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package cmd

import (
"errors"
"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
"os"
"path/filepath"
"strings"

"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
)

var cop bool
Expand Down
19 changes: 17 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,30 @@ package cmd

import (
"errors"
"strconv"
"strings"

"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
"strings"
)

func init() {
rootCmd.AddCommand(installCommand)
}

func maybeVersion(ver string) bool {
ver = strings.TrimLeft(ver, "vv")
splits := strings.Split(ver, ".")
hasNum := false
for _, s := range splits {
_, err := strconv.ParseInt(s, 10, 64)
if err == nil {
hasNum = true
}
}
return hasNum
}

var installCommand = &cobra.Command{
Use: "install <version>",
Short: "Installs Flutter SDK Version",
Expand Down Expand Up @@ -59,7 +74,7 @@ var installCommand = &cobra.Command{
version := args[0]
if fvmgo.IsValidFlutterChannel(version) {
err = fvmgo.FlutterChannelClone(version)
} else if !strings.HasPrefix(version, "v") {
} else if !maybeVersion(version) {
fvmgo.Errorf("It seems that you want install a Flutter channel but have a invalid channel")
channels := fvmgo.YellowV(strings.Join(fvmgo.FlutterChannels(), " "))
fvmgo.Errorf("Please use one of %v", channels)
Expand Down
1 change: 1 addition & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"errors"
"fmt"

"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
)
Expand Down
1 change: 1 addition & 0 deletions cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd

import (
"errors"

"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
)
Expand Down
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package cmd

import (
"fmt"
"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
"os"
"os/signal"

"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
)

var gVerbose bool
Expand Down
1 change: 1 addition & 0 deletions cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd

import (
"errors"

"github.com/befovy/fvm/fvmgo"
"github.com/spf13/cobra"
)
Expand Down
3 changes: 2 additions & 1 deletion fvmgo/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ limitations under the License.
package fvmgo

import (
"github.com/spf13/viper"
"os"
"path/filepath"

"github.com/spf13/viper"
)

var fvmEnvInited = false
Expand Down
16 changes: 9 additions & 7 deletions fvmgo/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ import (
"bytes"
"errors"
"fmt"
"github.com/spf13/viper"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/spf13/viper"
)

const FlutterRepo = "https://github.com/flutter/flutter.git"
const flutterRepo = "https://github.com/flutter/flutter.git"

// FlutterChannels returns All valid flutter channels as string array
func FlutterChannels() []string {
return []string{
"master", "stable", "dev", "beta",
Expand Down Expand Up @@ -70,13 +72,13 @@ func ProcessRunner(cmd string, dir string, arg ...string) error {
return nil
}

/// Returns true if it's a valid Flutter channel
// IsValidFlutterChannel return true if it's a valid Flutter channel
func IsValidFlutterChannel(channel string) bool {
channels := FlutterChannels()
return stringSliceContains(channels, channel)
}

/// Returns true if it's a valid Flutter channel
// IsValidFlutterVersion return true if it's a valid Flutter version\tag
func IsValidFlutterVersion(version string) bool {
initFvmEnv()
versions := viper.GetStringSlice("FLUTTER_REMOTE_TAGS")
Expand Down Expand Up @@ -162,7 +164,7 @@ func FlutterChannelClone(channel string) error {
if err != nil {
return errors.New(fmt.Sprintf("Cannot create directory for channel %s: %v", channel, err))
}
err = ProcessRunner("git", channelDir, "clone", "-b", channel, FlutterRepo, ".")
err = ProcessRunner("git", channelDir, "clone", "-b", channel, flutterRepo, ".")
if err != nil {
return err
}
Expand All @@ -187,7 +189,7 @@ func FlutterVersionClone(version string) error {
if err != nil {
return errors.New(fmt.Sprintf("Cannot creat directory for version %s: %v", version, err))
}
err = ProcessRunner("git", versionDir, "clone", "-b", version, FlutterRepo, ".")
err = ProcessRunner("git", versionDir, "clone", "-b", version, flutterRepo, ".")
if err != nil {
return err
}
Expand Down Expand Up @@ -241,7 +243,7 @@ func CheckIfGitExists() error {
}

func FlutterListAllSdks() []string {
runner := exec.Command("git", "ls-remote", "--tags", FlutterRepo)
runner := exec.Command("git", "ls-remote", "--tags", flutterRepo)
var b bytes.Buffer
runner.Stdout = &b

Expand Down

0 comments on commit 8b90a26

Please sign in to comment.