blob: 2819609eabbd33e0560c10120ee81985387913bf [file] [log] [blame]
// 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 'dart:async';
import 'package:file/file.dart';
import 'package:platform/platform.dart';
import 'common/core.dart';
import 'common/package_looping_command.dart';
import 'common/process_runner.dart';
import 'common/repository_package.dart';
/// A command to run Dart's "fix" command on packages.
class FixCommand extends PackageLoopingCommand {
/// Creates a fix command instance.
Directory packagesDir, {
ProcessRunner processRunner = const ProcessRunner(),
Platform platform = const LocalPlatform(),
}) : super(packagesDir, processRunner: processRunner, platform: platform);
final String name = 'fix';
final String description = 'Fixes packages using dart fix.\n\n'
'This command requires "dart" and "flutter" to be in your path, and '
'assumes that dependencies have already been fetched (e.g., by running '
'the analyze command first).';
final bool hasLongOutput = false;
PackageLoopingType get packageLoopingType =>
Future<PackageResult> runForPackage(RepositoryPackage package) async {
final int exitCode = await processRunner.runAndStream(
'dart', <String>['fix', '--apply'],
if (exitCode != 0) {
printError('Unable to automatically fix package.');
return PackageResult.success();