status.dart 1.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Copyright 2014 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 'package:args/command_runner.dart';
import 'package:file/file.dart';
import 'package:platform/platform.dart';

import './proto/conductor_state.pb.dart' as pb;
import './repository.dart';
import './state.dart';
import './stdio.dart';

const String kVerboseFlag = 'verbose';
const String kStateOption = 'state-file';

/// Command to print the status of the current Flutter release.
class StatusCommand extends Command<void> {
  StatusCommand({
20
    required this.checkouts,
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  })  : platform = checkouts.platform,
        fileSystem = checkouts.fileSystem,
        stdio = checkouts.stdio {
    final String defaultPath = defaultStateFilePath(platform);
    argParser.addOption(
      kStateOption,
      defaultsTo: defaultPath,
      help: 'Path to persistent state file. Defaults to $defaultPath',
    );
    argParser.addFlag(
      kVerboseFlag,
      abbr: 'v',
      defaultsTo: false,
      help: 'Also print logs.',
    );
  }

  final Checkouts checkouts;
  final FileSystem fileSystem;
  final Platform platform;
  final Stdio stdio;

  @override
  String get name => 'status';

  @override
  String get description => 'Print status of current release.';

  @override
  void run() {
51
    final File stateFile = checkouts.fileSystem.file(argResults![kStateOption]);
52 53
    if (!stateFile.existsSync()) {
      stdio.printStatus(
54
          'No persistent state file found at ${argResults![kStateOption]}.');
55 56
      return;
    }
57 58
    final pb.ConductorState state = readStateFromFile(stateFile);

59
    stdio.printStatus(presentState(state));
60
    if (argResults![kVerboseFlag] as bool) {
61 62 63 64 65
      stdio.printStatus('\nLogs:');
      state.logs.forEach(stdio.printStatus);
    }
  }
}