Skip to content

Commit

Permalink
Date formatting and test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Jun 22, 2020
1 parent fd86c94 commit 408a7cf
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 27 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ Flutter Version Management: A simple cli to manage Flutter SDK versions.

**Features:**

- Configure Flutter SDK version per project
- Configure and use 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
- Fast switch between Flutter channels & versions
- Dynamic sdk paths for IDE debugging support.
- Version FVM config with project for consistency across teams and CI environments.
- Set global Flutter version across projects

## Version Management

Expand Down Expand Up @@ -83,6 +85,14 @@ List all the versions that are installed on your machine. This command will also
> fvm list
```

### List Flutter Releases

Displays all Flutter releases, including the current version for `dev`, `beta` and `stable` channels.

```bash
> fvm releases
```

### Change FVM Cache Directory

There are some configurations that allows for added flexibility on FVM. If no `cache-path` is set, the default fvm path will be used.
Expand Down
6 changes: 3 additions & 3 deletions coverage_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions lib/commands/install.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ class InstallCommand extends Command {
Guards.isGitInstalled();

String version;
var hasConfig = false;
if (argResults.arguments.isEmpty) {
final configVersion = getConfigFlutterVersion();
if (configVersion == null) {
throw ExceptionMissingChannelVersion();
}
hasConfig = true;
version = configVersion;
} else {
version = argResults.arguments[0].toLowerCase();
Expand All @@ -45,5 +47,8 @@ class InstallCommand extends Command {
final flutterVersion = await inferFlutterVersion(version);

await installFlutterVersion(flutterVersion, skipSetup: skipSetup);
if (hasConfig) {
setAsProjectVersion(version);
}
}
}
37 changes: 17 additions & 20 deletions lib/commands/releases.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:args/command_runner.dart';
import 'package:console/console.dart';
import 'package:date_format/date_format.dart';
import 'package:io/ansi.dart';

import 'package:fvm/utils/releases_helper.dart';
import 'package:fvm/utils/version_installer.dart';

/// List installed SDK Versions
class ReleasesCommand extends Command {
Expand All @@ -20,26 +21,22 @@ class ReleasesCommand extends Command {
@override
void run() async {
final flutterReleases = await fetchReleases();
final channels = flutterReleases.currentRelease.toMap();

final list = <String>[];

channels.forEach((key, value) {
list.add('$key: $value');
});

var chooser = Chooser<String>(
list,
message: 'Select a release: ',
);

var version = chooser.chooseSync();

channels.forEach((key, value) {
if (version == '$key: $value') {
installFlutterVersion(value as String);
final channels = flutterReleases.currentRelease.toHashMap();
final releases = flutterReleases.releases.reversed;

releases.forEach((r) {
final channel = channels[r.version];
final channelOutput = green.wrap('$channel');
final version = yellow.wrap(r.version.padRight(17));
final pipe = Icon.PIPE_VERTICAL;
final friendlyDate =
formatDate(r.releaseDate, [M, ' ', d, ' ', yy]).padRight(10);
if (channel != null) {
print('----------$channelOutput----------');
print('$friendlyDate $pipe $version');
} else {
print('$friendlyDate $pipe $version');
}
});
print('You chose $version');
}
}
2 changes: 1 addition & 1 deletion lib/utils/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool isCurrentVersion(String version) {
/// The Flutter SDK Path referenced on FVM
String getFlutterSdkPath({String version}) {
var sdkVersion = version;
version ??= readProjectConfig().flutterSdkVersion;
sdkVersion ??= readProjectConfig().flutterSdkVersion;
return path.join(kVersionsDir.path, sdkVersion);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/utils/releases_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class CurrentRelease {
'dev': dev,
'stable': stable,
};

Map<String, dynamic> toHashMap() => {
'$beta': 'beta',
'$dev': 'dev',
'$stable': 'stable',
};
}

class Release {
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
path: ^1.6.4
process_run: ^0.10.10+1
http: ^0.12.1
date_format: ^1.0.8

dev_dependencies:
pedantic: ^1.8.0
Expand Down

0 comments on commit 408a7cf

Please sign in to comment.