Skip to content

Commit

Permalink
Made api a bit cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Mar 3, 2019
1 parent 8988302 commit 1f58a2a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 169 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ Use `fvm <version>` to install and activate a version of Flutter.
$ fvm stable
$ fvm beta

$ fvm release 1.2.1
$ fvm release 0.11.13
$ fvm 1.2.1
$ fvm 0.11.13


If `<version>` has already been installed, `fvm` will activate it from cache without having to download and set up again.

Lists all currently installed versions

$ fvm list
$ fvm
v1.2.1
> v0.11.13
master
Expand Down
78 changes: 0 additions & 78 deletions cmd/list.go

This file was deleted.

59 changes: 0 additions & 59 deletions cmd/release.go

This file was deleted.

78 changes: 50 additions & 28 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package cmd

import (
"errors"
"fmt"
"log"
"os"
"strings"

"github.com/leoafarias/fvm/lib"
"github.com/manifoldco/promptui"
Expand All @@ -32,39 +34,59 @@ var cfgFile string
var rootCmd = &cobra.Command{
Use: "fvm",
Short: "Lists all the installed versions of Flutter",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
return errors.New("Can only accept one argument")
}

return nil
},
// Uncomment the following line if your bare application
// has an action associated with it:
Run: func(cmd *cobra.Command, args []string) {
// var options []string
vs, err := lib.ListVersions()
if err != nil {
log.Fatal(err)
}

if len(vs) == 0 {
fmt.Println("No Flutter versions installed")
os.Exit(0)
}

templates := promptui.SelectTemplates{
Active: `👉 {{ .Name | cyan | bold }}`,
Inactive: ` {{ .Name | cyan }}`,
Selected: `{{ "✔" | green | bold }} {{ "Channel" | bold }}: {{ .Name | cyan }}`,
}

list := promptui.Select{
Label: "Choose Installed Versions",
Items: vs,
Templates: &templates,
}

i, _, err := list.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
if len(args) == 1 {
var version string
if strings.HasPrefix(args[0], "v") {
version = args[0]
} else {
version = "v" + args[0]
}
lib.LoadVersion(version)

} else {

// var options []string
vs, err := lib.ListVersions()
if err != nil {
log.Fatal(err)
}

if len(vs) == 0 {
fmt.Println("No Flutter versions installed")
os.Exit(0)
}

templates := promptui.SelectTemplates{
Active: `👉 {{ .Name | cyan | bold }}`,
Inactive: ` {{ .Name | cyan }}`,
Selected: `{{ "✔" | green | bold }} {{ "Channel" | bold }}: {{ .Name | cyan }}`,
}

list := promptui.Select{
Label: "Choose Installed Versions",
Items: vs,
Templates: &templates,
}

i, _, err := list.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}

lib.LoadVersion(vs[i].Name)
}

lib.LoadVersion(vs[i].Name)
},
}

Expand Down
5 changes: 4 additions & 1 deletion lib/fvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ func setup(v Version) (Version, error) {

// If directory doesnt exists get the channel
if v.dir == false {
fluttertools.GetChannel(workspaceHome, v.Name)
if err := fluttertools.GetChannel(workspaceHome, v.Name); err != nil {
log.Fatal(err)
return Version{}, err
}
v.dir = true
}

Expand Down

0 comments on commit 1f58a2a

Please sign in to comment.