diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1c3288b..f1e8675 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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/... diff --git a/.gitignore b/.gitignore index 7f03acf..f3b6fc4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .idea/ fvm.iml -.DS_Store \ No newline at end of file +.DS_Store + +# binary +fvm \ No newline at end of file diff --git a/cmd/current.go b/cmd/current.go index 7556fea..a1a4b78 100644 --- a/cmd/current.go +++ b/cmd/current.go @@ -17,9 +17,10 @@ package cmd import ( "errors" - "github.com/befovy/fvm/fvmgo" "os" + "github.com/befovy/fvm/fvmgo" + "github.com/spf13/cobra" ) diff --git a/cmd/flutter.go b/cmd/flutter.go index fcd1099..b45bdd8 100644 --- a/cmd/flutter.go +++ b/cmd/flutter.go @@ -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() { diff --git a/cmd/import.go b/cmd/import.go index 5ccc2e2..58c1302 100644 --- a/cmd/import.go +++ b/cmd/import.go @@ -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 diff --git a/cmd/install.go b/cmd/install.go index faffa04..67951ab 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -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 ", Short: "Installs Flutter SDK Version", @@ -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) diff --git a/cmd/list.go b/cmd/list.go index 570e5a7..28c6c63 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -18,6 +18,7 @@ package cmd import ( "errors" "fmt" + "github.com/befovy/fvm/fvmgo" "github.com/spf13/cobra" ) diff --git a/cmd/remove.go b/cmd/remove.go index 7d7f080..b506414 100644 --- a/cmd/remove.go +++ b/cmd/remove.go @@ -17,6 +17,7 @@ package cmd import ( "errors" + "github.com/befovy/fvm/fvmgo" "github.com/spf13/cobra" ) diff --git a/cmd/root.go b/cmd/root.go index 99290c7..42d106d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 diff --git a/cmd/use.go b/cmd/use.go index 4e12562..5594767 100644 --- a/cmd/use.go +++ b/cmd/use.go @@ -17,6 +17,7 @@ package cmd import ( "errors" + "github.com/befovy/fvm/fvmgo" "github.com/spf13/cobra" ) diff --git a/fvmgo/path.go b/fvmgo/path.go index 53c8fd2..e089aaf 100644 --- a/fvmgo/path.go +++ b/fvmgo/path.go @@ -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 diff --git a/fvmgo/tool.go b/fvmgo/tool.go index bd731af..b7b1600 100644 --- a/fvmgo/tool.go +++ b/fvmgo/tool.go @@ -19,7 +19,6 @@ import ( "bytes" "errors" "fmt" - "github.com/spf13/viper" "io" "io/ioutil" "os" @@ -27,10 +26,13 @@ import ( "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", @@ -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") @@ -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 } @@ -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 } @@ -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