|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | | -import 'dart:async'; |
6 | | -import 'dart:io'; |
| 5 | +import 'package:build_runner/src/build_runner.dart'; |
7 | 6 |
|
8 | | -import 'package:args/args.dart'; |
9 | | -import 'package:args/command_runner.dart'; |
10 | | -import 'package:build_runner/src/build_script_generate/bootstrap.dart'; |
11 | | -import 'package:build_runner/src/build_script_generate/build_process_state.dart'; |
12 | | -import 'package:build_runner/src/entrypoint/options.dart'; |
13 | | -import 'package:build_runner/src/entrypoint/runner.dart'; |
14 | | -import 'package:build_runner_core/build_runner_core.dart'; |
15 | | -import 'package:io/ansi.dart'; |
16 | | -import 'package:io/io.dart'; |
17 | | - |
18 | | -import 'src/commands/clean.dart'; |
19 | | - |
20 | | -Future<void> main(List<String> args) async { |
21 | | - // Use the actual command runner to parse the args and immediately print the |
22 | | - // usage information if there is no command provided or the help command was |
23 | | - // explicitly invoked. |
24 | | - var commandRunner = BuildCommandRunner( |
25 | | - [], |
26 | | - await PackageGraph.forThisPackage(), |
27 | | - ); |
28 | | - var localCommands = [CleanCommand()]; |
29 | | - var localCommandNames = localCommands.map((c) => c.name).toSet(); |
30 | | - for (var command in localCommands) { |
31 | | - commandRunner.addCommand(command); |
32 | | - // This flag is added to each command individually and not the top level. |
33 | | - command.argParser.addFlag( |
34 | | - verboseOption, |
35 | | - abbr: 'v', |
36 | | - defaultsTo: false, |
37 | | - negatable: false, |
38 | | - help: 'Verbose logging: displays info logged by builders.', |
39 | | - ); |
40 | | - } |
41 | | - |
42 | | - ArgResults parsedArgs; |
43 | | - try { |
44 | | - parsedArgs = commandRunner.parse(args); |
45 | | - } on UsageException catch (e) { |
46 | | - print(red.wrap(e.message)); |
47 | | - print(''); |
48 | | - print(e.usage); |
49 | | - exitCode = ExitCode.usage.code; |
50 | | - return; |
51 | | - } |
52 | | - |
53 | | - var commandName = parsedArgs.command?.name; |
54 | | - |
55 | | - if (parsedArgs.rest.isNotEmpty) { |
56 | | - print( |
57 | | - yellow.wrap('Could not find a command named "${parsedArgs.rest[0]}".'), |
58 | | - ); |
59 | | - print(''); |
60 | | - print(commandRunner.usageWithoutDescription); |
61 | | - exitCode = ExitCode.usage.code; |
62 | | - return; |
63 | | - } |
64 | | - |
65 | | - if (commandName == 'help' || |
66 | | - parsedArgs.wasParsed('help') || |
67 | | - (parsedArgs.command?.wasParsed('help') ?? false)) { |
68 | | - await commandRunner.runCommand(parsedArgs); |
69 | | - return; |
70 | | - } |
71 | | - |
72 | | - if (commandName == null) { |
73 | | - commandRunner.printUsage(); |
74 | | - exitCode = ExitCode.usage.code; |
75 | | - return; |
76 | | - } |
77 | | - |
78 | | - if (localCommandNames.contains(commandName)) { |
79 | | - exitCode = await commandRunner.runCommand(parsedArgs) ?? 1; |
80 | | - } else { |
81 | | - var experiments = parsedArgs.command!['enable-experiment'] as List<String>?; |
82 | | - // Set the buildLog mode before the command starts so the first few log |
83 | | - // messages are displayed correctly. |
84 | | - switch (commandName) { |
85 | | - case 'build': |
86 | | - case 'serve': |
87 | | - case 'watch': |
88 | | - case 'test': |
89 | | - buildLog.configuration = buildLog.configuration.rebuild((b) { |
90 | | - b.mode = BuildLogMode.build; |
91 | | - }); |
92 | | - case 'daemon': |
93 | | - buildLog.configuration = buildLog.configuration.rebuild((b) { |
94 | | - b.mode = BuildLogMode.daemon; |
95 | | - }); |
96 | | - } |
97 | | - while ((exitCode = await generateAndRun(args, experiments: experiments)) == |
98 | | - ExitCode.tempFail.code) {} |
99 | | - } |
100 | | -} |
| 7 | +Future<void> main(List<String> arguments) => |
| 8 | + BuildRunner(arguments: arguments, builders: null).run(); |
0 commit comments