Skip to content

Commit 0714128

Browse files
authored
[infra] Default CI scrip tasks all to false (#2529)
I find myself wanting to run `dart tools/ci.dart --coverage` and not wanting to write `dart tools/ci.dart --none --coverage`. Also, it's kinda hard to remember what tasks are run by default or not. So it's probably better to not run anything by default.
1 parent cdb263e commit 0714128

File tree

1 file changed

+13
-51
lines changed

1 file changed

+13
-51
lines changed

tool/ci.dart

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ void main(List<String> arguments) async {
1313

1414
final ArgResults argResults = parser.parse(arguments);
1515

16-
if (argResults['all'] as bool && argResults['none'] as bool) {
17-
print('Error: --all and --none are mutually exclusive.');
18-
exit(1);
19-
}
20-
2116
final packages = loadPackagesFromPubspec();
2217

2318
if (argResults['help'] as bool) {
@@ -33,10 +28,14 @@ void main(List<String> arguments) async {
3328
return;
3429
}
3530

36-
for (final task in tasks) {
37-
if (task.shouldRun(argResults)) {
38-
await task.run(packages: packages, argResults: argResults);
39-
}
31+
final tasksToRun = tasks.where((task) => task.shouldRun(argResults)).toList();
32+
if (tasksToRun.isEmpty) {
33+
print('No tasks specified. Please specify at least one task to run.');
34+
exit(1);
35+
}
36+
37+
for (final task in tasksToRun) {
38+
await task.run(packages: packages, argResults: argResults);
4039
}
4140
}
4241

@@ -52,19 +51,9 @@ ArgParser makeArgParser() {
5251
'all',
5352
negatable: false,
5453
help: 'Enable all tasks. Overridden by --no-<task> flags.',
55-
)
56-
..addFlag(
57-
'none',
58-
negatable: false,
59-
help: 'Disable all tasks. Overridden by --<task> flags.',
6054
);
6155
for (final task in tasks) {
62-
parser.addFlag(
63-
task.name,
64-
help:
65-
'${task.helpMessage}\n'
66-
'(defaults to ${task.defaultValue})',
67-
);
56+
parser.addFlag(task.name, help: task.helpMessage);
6857
}
6958
return parser;
7059
}
@@ -84,35 +73,21 @@ abstract class Task {
8473
/// For example, a name of 'analyze' corresponds to the `--[no-]analyze` flag.
8574
final String name;
8675

87-
/// The default state of the task if no master flag (`--all` or `--none`) is
88-
/// provided.
89-
final bool defaultValue;
90-
9176
/// The base help message for the task's command-line flag.
92-
///
93-
/// The `(defaults to ...)` text is added automatically.
9477
final String helpMessage;
9578

96-
const Task({
97-
required this.name,
98-
required this.defaultValue,
99-
required this.helpMessage,
100-
});
79+
const Task({required this.name, required this.helpMessage});
10180

10281
bool shouldRun(ArgResults argResults) {
103-
final useNone = argResults['none'] as bool;
10482
final useAll = argResults['all'] as bool;
10583

10684
if (argResults.wasParsed(name)) {
10785
return argResults[name] as bool;
10886
}
109-
if (useNone) {
110-
return false;
111-
}
11287
if (useAll) {
11388
return true;
11489
}
115-
return defaultValue;
90+
return false;
11691
}
11792

11893
Future<void> run({
@@ -128,7 +103,6 @@ class PubTask extends Task {
128103
const PubTask()
129104
: super(
130105
name: 'pub',
131-
defaultValue: false,
132106
helpMessage:
133107
'Run `dart pub get` on the root and non-workspace packages.\n'
134108
'Run `dart pub global activate coverage`.',
@@ -155,7 +129,6 @@ class AnalyzeTask extends Task {
155129
const AnalyzeTask()
156130
: super(
157131
name: 'analyze',
158-
defaultValue: true,
159132
helpMessage: 'Run `dart analyze` on the packages.',
160133
);
161134

@@ -171,11 +144,7 @@ class AnalyzeTask extends Task {
171144
/// Checks for code formatting issues with `dart format`.
172145
class FormatTask extends Task {
173146
const FormatTask()
174-
: super(
175-
name: 'format',
176-
defaultValue: true,
177-
helpMessage: 'Run `dart format` on the packages.',
178-
);
147+
: super(name: 'format', helpMessage: 'Run `dart format` on the packages.');
179148

180149
@override
181150
Future<void> run({
@@ -196,11 +165,7 @@ class FormatTask extends Task {
196165
/// This is used to keep generated files in sync with their sources.
197166
class GenerateTask extends Task {
198167
const GenerateTask()
199-
: super(
200-
name: 'generate',
201-
defaultValue: true,
202-
helpMessage: 'Run code generation scripts.',
203-
);
168+
: super(name: 'generate', helpMessage: 'Run code generation scripts.');
204169

205170
@override
206171
Future<void> run({
@@ -226,7 +191,6 @@ class TestTask extends Task {
226191
const TestTask()
227192
: super(
228193
name: 'test',
229-
defaultValue: true,
230194
helpMessage:
231195
'Run `dart test` on the packages.\n'
232196
'Implied by --coverage.',
@@ -259,7 +223,6 @@ class ExampleTask extends Task {
259223
const ExampleTask()
260224
: super(
261225
name: 'example',
262-
defaultValue: true,
263226
helpMessage: 'Run tests and executables for examples.',
264227
);
265228

@@ -317,7 +280,6 @@ class CoverageTask extends Task {
317280
const CoverageTask()
318281
: super(
319282
name: 'coverage',
320-
defaultValue: false,
321283
helpMessage:
322284
'Collect coverage information on the packages.\n'
323285
'Implies --test.',

0 commit comments

Comments
 (0)