-
Notifications
You must be signed in to change notification settings - Fork 236
/
flutter_command.dart
63 lines (53 loc) · 1.79 KB
/
flutter_command.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import 'package:args/args.dart';
import '../models/cache_flutter_version_model.dart';
import '../services/logger_service.dart';
import '../services/project_service.dart';
import '../utils/commands.dart';
import '../utils/constants.dart';
import '../utils/exceptions.dart';
import '../workflows/ensure_cache.workflow.dart';
import 'base_command.dart';
/// Proxies Flutter Commands
class FlutterCommand extends BaseCommand {
@override
final name = 'flutter';
@override
final description = 'Proxies Flutter Commands';
@override
final argParser = ArgParser.allowAnything();
/// Constructor
FlutterCommand();
@override
Future<int> run() async {
final version = ProjectService.fromContext.findVersion();
final args = [...?argResults?.arguments];
CacheFlutterVersion? cacheVersion;
if (version != null) {
// Will install version if not already installed
cacheVersion = await ensureCacheWorkflow(version);
logger
..detail('$kPackageName: Running Flutter SDK from version $version')
..detail('');
void checkIfUpgradeCommand(List<String> args) {
if (args.isNotEmpty && args.first == 'upgrade') {
throw AppException(
'You should not upgrade a release version. '
'Please install a channel instead to upgrade it. ',
);
}
}
// If its not a channel silence version check
if (!cacheVersion.isChannel) {
checkIfUpgradeCommand(args);
}
// Runs flutter command with pinned version
} else {
logger
..detail('$kPackageName: Running Flutter SDK from PATH')
..detail('');
// Running null will default to flutter version on paths
}
final results = await runFlutter(args, version: cacheVersion);
return results.exitCode;
}
}