format.dart 1.3 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

7 8 9
import 'package:args/args.dart';

import '../artifacts.dart';
10
import '../base/common.dart';
11
import '../base/process.dart';
12
import '../globals.dart' as globals;
13 14 15
import '../runner/flutter_command.dart';

class FormatCommand extends FlutterCommand {
16 17 18
  @override
  ArgParser get argParser => _argParser;
  final ArgParser _argParser = ArgParser.allowAnything();
19

20 21 22 23 24 25 26 27 28
  @override
  final String name = 'format';

  @override
  List<String> get aliases => const <String>['dartfmt'];

  @override
  final String description = 'Format one or more dart files.';

29
  @override
30
  String get invocation => '${runner.executableName} $name <one or more paths>';
31 32

  @override
33
  bool get shouldUpdateCache => false;
34

35 36 37
  @override
  Future<FlutterCommandResult> runCommand() async {
    final String dartBinary = globals.artifacts.getArtifactPath(Artifact.engineDartBinary);
38
    final List<String> command = <String>[
39 40
      dartBinary,
      'format',
41 42
      ...argResults.rest,
    ];
43

44
    final int result = await processUtils.stream(command);
45
    if (result != 0) {
46
      throwToolExit('', exitCode: result);
47
    }
48
    return FlutterCommandResult.success();
49 50
  }
}