Skip to content

Commit

Permalink
Merge pull request #87 from leoafarias/feature/force-flag
Browse files Browse the repository at this point in the history
Feature/force flag
  • Loading branch information
leoafarias authored Jul 16, 2020
2 parents 10ff074 + 5667cc5 commit ff2190d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,24 @@ You can use different Flutter SDK versions per project. To do that you have to g
> fvm use <version>
```

**Set Global Version**

If you want to use a specific version by default in your machine, you can specify the flag `--global` to the `use` command. A symbolic link to the Flutter version will be created in the `fvm` home folder, which you could then add to your PATH environment variable as follows: `FVM_HOME/default/bin`. Use `fvm use --help`, this will give you the exact path you need to configure.

```bash
> fvm use <version> --global
```

**Force Flag**

Fvm only allows to call the use command on Flutter projects. However if you want to call the `use` command on a non-flutter directory use the `--force` flag.

If you are starting a new project and plan on using `fvm flutter create` you wil have to use the `--force` flag

```bash
> fvm use <version> --force
```

### 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.
Expand Down
12 changes: 9 additions & 3 deletions lib/commands/use.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ class UseCommand extends Command {
help:
'Sets version as the global version.\nMake sure Flutter PATH env is set to: $kDefaultFlutterPath',
negatable: false,
)
..addFlag(
'force',
help: 'Skips command guards that does Flutter project checks.',
negatable: false,
);
}

@override
Future<void> run() async {
final useGlobally = argResults['global'] == true;
final isGlobal = argResults['global'] == true;
final isForced = argResults['force'] == true;
final version = argResults.rest[0];

if (argResults.rest.isEmpty) {
Expand All @@ -37,12 +43,12 @@ class UseCommand extends Command {
// Make sure is valid Flutter version
final flutterVersion = await inferFlutterVersion(version);
// If project use check that is Flutter project
if (!useGlobally) Guards.isFlutterProject();
if (!isGlobal && !isForced) Guards.isFlutterProject();

// Make sure version is installed
await checkAndInstallVersion(flutterVersion);

if (useGlobally) {
if (isGlobal) {
// Sets version as the global
setAsGlobalVersion(flutterVersion);
} else {
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/guards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Guards {
static void isFlutterProject() {
final isFlutter = kLocalProjectPubspec.existsSync();
if (!isFlutter) {
throw Exception('Run this FVM command at the root of a Flutter project');
throw Exception(
'Run this FVM command at the root of a Flutter project or use --force to bypass this.');
}
}

Expand Down

0 comments on commit ff2190d

Please sign in to comment.