This repository has been archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
/
Copy pathcommand_runner.dart
114 lines (104 loc) · 3.01 KB
/
command_runner.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:engine_build_configs/engine_build_configs.dart';
import '../environment.dart';
import 'build_command.dart';
import 'cleanup_command.dart';
import 'fetch_command.dart';
import 'flags.dart';
import 'format_command.dart';
import 'lint_command.dart';
import 'query_command.dart';
import 'run_command.dart';
import 'test_command.dart';
const int _usageLineLength = 100;
/// The root command runner.
final class ToolCommandRunner extends CommandRunner<int> {
/// Constructs the runner and populates commands, subcommands, and global
/// options and flags.
ToolCommandRunner({
required this.environment,
required this.configs,
this.help = false,
}) : super(
'et',
''
'A command line tool for working on '
'the Flutter Engine.\n\nThis is a community supported project, '
'for more information see https://flutter.dev/to/et.',
usageLineLength: _usageLineLength,
) {
final List<Command<int>> commands = <Command<int>>[
CleanupCommand(
environment: environment,
usageLineLength: _usageLineLength,
),
FetchCommand(
environment: environment,
usageLineLength: _usageLineLength,
),
FormatCommand(
environment: environment,
usageLineLength: _usageLineLength,
),
QueryCommand(
environment: environment,
configs: configs,
help: help,
usageLineLength: _usageLineLength,
),
BuildCommand(
environment: environment,
configs: configs,
help: help,
usageLineLength: _usageLineLength,
),
RunCommand(
environment: environment,
configs: configs,
usageLineLength: _usageLineLength,
),
LintCommand(
environment: environment,
usageLineLength: _usageLineLength,
),
TestCommand(
environment: environment,
configs: configs,
help: help,
usageLineLength: _usageLineLength,
),
];
commands.forEach(addCommand);
argParser.addFlag(
verboseFlag,
abbr: 'v',
help: 'Prints verbose output',
negatable: false,
);
}
/// The host system environment.
final Environment environment;
/// Build configurations loaded from the engine from under ci/builders.
final Map<String, BuilderConfig> configs;
/// Whether the invocation is for a help command
final bool help;
@override
Future<int> run(Iterable<String> args) async {
try {
return await runCommand(parse(args)) ?? 0;
} on FormatException catch (e, s) {
environment.logger.error('$e\n$s');
return 1;
} on UsageException catch (e) {
environment.logger.error(e);
return 1;
}
}
@override
void printUsage() {
environment.logger.status(usage);
}
}