Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: first version of fvm. All commands are available
- Loading branch information
Showing
17 changed files
with
1,004 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
fvm.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,125 @@ | ||
# fvm | ||
Flutter Version Manager | ||
# `fvm` | ||
|
||
Flutter Version Management: A simple cli to manage Flutter SDK versions. | ||
|
||
**Go port of [leoafarias/fvm](https://github.com/leoafarias/fvm)** | ||
|
||
**Features:** | ||
|
||
* Configure Flutter SDK version per project | ||
* Ability to install and cache multiple Flutter SDK Versions | ||
* Easily switch between Flutter channels & versions | ||
* Per project Flutter SDK upgrade | ||
|
||
## Version Management | ||
|
||
This tool allows you to manage multiple channels and releases, and caches these versions locally, so you don't have to wait for a full setup every time you want to switch versions. | ||
|
||
Also, it allows you to grab versions by a specific release, i.e. 1.2.0. In case you have projects in different Flutter SDK versions and do not want to upgrade. | ||
|
||
## Usage | ||
|
||
To Install: | ||
|
||
```bash | ||
> go get -u -v github.com/befovy/fvm | ||
``` | ||
|
||
And then, for information on each command: | ||
|
||
```bash | ||
> fvm help | ||
``` | ||
|
||
### Install a SDK Version | ||
|
||
FVM gives you the ability to install many Flutter **releases** or **channels**. | ||
|
||
```bash | ||
> fvm install <version> | ||
``` | ||
|
||
Version - use `master` to install the Master channel and `v1.8.0` to install the release. | ||
|
||
### Use a SDK Version | ||
|
||
You can use different Flutter SDK versions per project. To do that you have to go into the root of the project and: | ||
|
||
```bash | ||
> fvm use <version> | ||
``` | ||
|
||
### Remove a SDK Version | ||
|
||
Using the remove command will uninstall the SDK version locally. This will impact any projects that depend on that version of the SDK. | ||
|
||
```bash | ||
> fvm remove <version> | ||
``` | ||
|
||
### List Installed Versions | ||
|
||
List all the versions that are installed on your machine. | ||
|
||
```bash | ||
> fvm list | ||
``` | ||
|
||
### Change FVM Cache Directory | ||
|
||
There are some configurations that allows for added flexibility on FVM. | ||
|
||
```bash | ||
fvm config --cache-path <path-to-use> | ||
``` | ||
|
||
### List Config Options | ||
|
||
Returns list of all stored options in the config file. | ||
|
||
```bash | ||
fvm config --ls | ||
``` | ||
|
||
### Running Flutter SDK | ||
|
||
There are a couple of ways you can interact with the SDK setup in your project. | ||
|
||
#### Proxy Commands | ||
|
||
Flutter command within `fvm` proxies all calls to the CLI just changing the SDK to be the local one. | ||
|
||
```bash | ||
> fvm flutter run | ||
``` | ||
|
||
This will run `flutter run` command using the local project SDK. If no FVM config is found in the project. FMV will recursively try for a version in a parent directory. | ||
|
||
#### Call Local SDK Directly | ||
|
||
FVM creates a symbolic link within your project called **fvm** which links to the installed version of the SDK. | ||
|
||
```bash | ||
> ./fvm run | ||
``` | ||
|
||
This will run `flutter run` command using the local project SDK. | ||
|
||
As an example calling `fvm flutter run` is the equivalent of calling `flutter run` using the local project SDK. | ||
|
||
### Configure Your IDE | ||
|
||
#### VSCode | ||
|
||
Add the following to your settings.json | ||
|
||
```json | ||
|
||
"dart.flutterSdkPaths": [ | ||
"fvm" | ||
] | ||
``` | ||
|
||
## License | ||
|
||
This project is licensed under the Apache License 2.0 License - see the [LICENSE](LICENSE) file for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"github.com/befovy/fvm/internal/config" | ||
"github.com/befovy/fvm/internal/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cfg_cache_path string | ||
cfg_list bool | ||
) | ||
|
||
func init() { | ||
configCommand.Flags().BoolVar(&cfg_list, "ls", false, "Lists all config options") | ||
configCommand.Flags().StringVarP(&cfg_cache_path, "cache-path", "c", "", "Path to store Flutter cached versions") | ||
rootCmd.AddCommand(configCommand) | ||
} | ||
|
||
var configCommand = &cobra.Command{ | ||
Use: "config", | ||
Short: "Config fvm options", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) != 0 { | ||
return errors.New("dose not take argument") | ||
} | ||
return nil | ||
}, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(cfg_cache_path) > 0 { | ||
config.SetFlutterStoragePath(cfg_cache_path) | ||
} | ||
if cfg_list { | ||
all := config.AllConfig() | ||
if len(all) > 0 { | ||
log.Infof(all) | ||
} else { | ||
log.Warnf("No configuration has been set") | ||
} | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/befovy/fvm/internal/constants" | ||
"github.com/befovy/fvm/internal/fileutil" | ||
"github.com/befovy/fvm/internal/log" | ||
"github.com/befovy/fvm/internal/tool" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(flutterCommand) | ||
} | ||
|
||
var flutterCommand = &cobra.Command{ | ||
Use: "flutter", | ||
Short: "Proxies Flutter Commands", | ||
DisableFlagParsing:true, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
link := tool.ProjectFlutterLink() | ||
if len(link) == 0 || !fileutil.IsSymlink(link) { | ||
log.Errorf("No FVM config found. Create with <use> command") | ||
} else { | ||
|
||
dst, err := os.Readlink(link) | ||
if err != nil { | ||
log.Errorf("Cannot read link target: %v", err) | ||
os.Exit(1) | ||
} | ||
tool.ProcessRunner(dst, constants.WorkingDirectory(), args...) | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"github.com/befovy/fvm/internal/tool" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(installCommand) | ||
} | ||
|
||
var installCommand = &cobra.Command{ | ||
Use: "install <version>", | ||
Short: "Installs Flutter SDK Version", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return errors.New("need to provide a channel or a version") | ||
} | ||
if len(args) > 1 { | ||
return errors.New("allows only one argument, the version or branch to install") | ||
} | ||
return nil | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
tool.CheckIfGitExists() | ||
version := args[0] | ||
isChannel := tool.IsValidFlutterChannel(version) | ||
if isChannel { | ||
tool.FlutterChannelClone(version) | ||
} else { | ||
tool.FlutterVersionClone(version) | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/befovy/fvm/internal/log" | ||
"github.com/befovy/fvm/internal/tool" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(listCommand) | ||
} | ||
|
||
var listCommand = &cobra.Command{ | ||
Use: "list", | ||
Short: "Lists installed Flutter SDK Version", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) != 0 { | ||
return errors.New("dose not take argument") | ||
} | ||
return nil | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
choices := tool.FlutterListInstalledSdks() | ||
if len(choices) == 0 { | ||
log.Warnf("No SDKs have been installed yet.") | ||
} else { | ||
for _, c := range choices { | ||
if tool.IsCurrentVersion(c) { | ||
c = fmt.Sprintf("%s (current)", c) | ||
} | ||
log.Infof(c) | ||
} | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"github.com/befovy/fvm/internal/log" | ||
"github.com/befovy/fvm/internal/tool" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(removeCommand) | ||
} | ||
|
||
var removeCommand = &cobra.Command{ | ||
Use: "remove <version>", | ||
Short:"Removes Flutter SDK Version", | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return errors.New("need to provide a channel or a version") | ||
} | ||
if len(args) > 1 { | ||
return errors.New("allows only one argument, the version or branch to remove") | ||
} | ||
return nil | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
version := args[0] | ||
isValidInstall := tool.IsValidFlutterInstall(version) | ||
if !isValidInstall { | ||
log.Warnf("Flutter SDK: %s is not installed", version) | ||
} else { | ||
log.Infof("Removing %s", version) | ||
tool.FlutterSdkRemove(version) | ||
log.Infof("Removing %s finished", version) | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/befovy/fvm/internal/log" | ||
) | ||
|
||
//var colors bool | ||
var verbose bool | ||
|
||
func init() { | ||
// rootCmd.PersistentFlags().BoolVar(&colors, "colors", true, "Add Colors to log") | ||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Print verbose output") | ||
} | ||
|
||
func initFvm() { | ||
log.Colorize() | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt, os.Kill) | ||
go func() { | ||
for range c { | ||
fmt.Println("Killed") | ||
os.Exit(1) | ||
} | ||
}() | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "fvm", | ||
Short: "Flutter Version Management", | ||
Long: "Flutter Version Management: A cli to manage Flutter SDK versions.", | ||
} | ||
|
||
// Execute executes the rootCmd | ||
func Execute() { | ||
cobra.OnInitialize(initFvm) | ||
if err := rootCmd.Execute(); err != nil { | ||
log.Errorf("Command failed: %v", err) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.