blob: 50643263bf8d99962c91872ad4bc4242e4c8bac2 [file] [log] [blame]
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. 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:analyzer/src/dart/analysis/experiments.dart';
import 'package:dartdev/src/core.dart';
import 'package:nnbd_migration/migration_cli.dart';
class MigrateCommand extends DartdevCommand {
static const String cmdName = 'migrate';
static const String cmdDescription =
'Perform null safety migration on a project.';
/// Return whether the SDK has null safety on by default.
static bool get nullSafetyOnByDefault => IsEnabledByDefault.non_nullable;
final bool verbose;
MigrateCommand({this.verbose = false})
: super(cmdName, '$cmdDescription\n\n${MigrationCli.migrationGuideLink}',
verbose) {
MigrationCli.defineOptions(argParser, !verbose);
}
@override
String get invocation {
return '${super.invocation} [project or directory]';
}
@override
FutureOr<int> run() async {
var cli = MigrationCli(binaryName: 'dart $name');
try {
await cli.decodeCommandLineArgs(argResults!, isVerbose: verbose)?.run();
} on MigrationExit catch (migrationExit) {
return migrationExit.exitCode;
}
return 0;
}
}