Add a command-line option to dartfix to specify the output directory

Change-Id: I5cc1b73427f95554bf2f20aa54923d9c3808e1f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117463
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson
2019-09-17 13:46:27 +00:00
committed by commit-bot@chromium.org
parent b87c9afb82
commit e00c8f3cb7
3 changed files with 33 additions and 10 deletions
+9
View File
@@ -16,6 +16,7 @@ import 'package:dartfix/listener/bad_message_listener.dart';
import 'package:dartfix/src/context.dart';
import 'package:dartfix/src/options.dart';
import 'package:dartfix/src/util.dart';
import 'package:path/path.dart' as path;
import 'package:pub_semver/pub_semver.dart';
class Driver {
@@ -127,6 +128,14 @@ class Driver {
if (options.pedanticFixes) {
params.includePedanticFixes = true;
}
String dir = options.outputDir;
if (dir != null) {
if (!path.isAbsolute(dir)) {
dir = path.absolute(dir);
}
dir = path.canonicalize(dir);
params.outputDir = dir;
}
Map<String, dynamic> json =
await server.send(EDIT_REQUEST_DARTFIX, params.toJson());
+12 -4
View File
@@ -9,19 +9,20 @@ import 'package:cli_util/cli_logging.dart';
import 'package:dartfix/src/context.dart';
import 'package:path/path.dart' as path;
const excludeFixOption = 'excludeFix';
const forceOption = 'force';
const includeFixOption = 'fix';
const excludeFixOption = 'excludeFix';
const outputDirOption = 'outputDir';
const overwriteOption = 'overwrite';
const pedanticOption = 'pedantic';
const requiredOption = 'required';
const _binaryName = 'dartfix';
const _colorOption = 'color';
const _serverSnapshot = 'server';
const _helpOption = 'help';
// options only supported by server 1.22.2 and greater
const _helpOption = 'help';
const _serverSnapshot = 'server';
const _verboseOption = 'verbose';
/// Command line options for `dartfix`.
@@ -40,6 +41,7 @@ class Options {
final bool force;
final bool showHelp;
final String outputDir;
final bool overwrite;
final bool useColor;
final bool verbose;
@@ -48,6 +50,7 @@ class Options {
: force = results[forceOption] as bool,
includeFixes = (results[includeFixOption] as List ?? []).cast<String>(),
excludeFixes = (results[excludeFixOption] as List ?? []).cast<String>(),
outputDir = results[outputDirOption] as String,
overwrite = results[overwriteOption] as bool,
pedanticFixes = results[pedanticOption] as bool,
requiredFixes = results[requiredOption] as bool,
@@ -104,7 +107,12 @@ class Options {
negatable: false)
..addFlag(_colorOption,
help: 'Use ansi colors when printing messages.',
defaultsTo: Ansi.terminalSupportsAnsi);
defaultsTo: Ansi.terminalSupportsAnsi)
//
// Hidden options.
//
..addOption(outputDirOption,
help: 'Path to the output directory', hide: true);
context ??= Context();
+12 -6
View File
@@ -30,6 +30,7 @@ main() {
String normalOut,
bool pedanticFixes = false,
bool requiredFixes = false,
String outputDir,
bool overwrite = false,
String serverSnapshot,
List<String> targetSuffixes,
@@ -55,6 +56,7 @@ main() {
expect(options.force, force);
expect(options.pedanticFixes, pedanticFixes);
expect(options.requiredFixes, requiredFixes);
expect(options.outputDir, outputDir);
expect(options.overwrite, overwrite);
expect(options.serverSnapshot, serverSnapshot);
expect(options.showHelp, showHelp);
@@ -115,6 +117,10 @@ main() {
errorOut: 'Expected directory, but found', exitCode: 21);
});
test('outputDir', () {
parse(['--outputDir=bar', 'foo'], outputDir: 'bar');
});
test('overwrite', () {
parse(['--overwrite', 'foo'], overwrite: true, targetSuffixes: ['foo']);
});
@@ -145,12 +151,6 @@ main() {
});
}
void expectOneFileTarget(Options options, String fileName) {
expect(options.targets, hasLength(1));
final target = options.targets[0];
expect(target.endsWith(fileName), isTrue);
}
void expectContains(Iterable<String> collection, String suffix) {
for (String elem in collection) {
if (elem.endsWith(suffix)) {
@@ -159,3 +159,9 @@ void expectContains(Iterable<String> collection, String suffix) {
}
fail('Expected one of $collection\n to end with "$suffix"');
}
void expectOneFileTarget(Options options, String fileName) {
expect(options.targets, hasLength(1));
final target = options.targets[0];
expect(target.endsWith(fileName), isTrue);
}