blob: cb83e8250bd581701bca1658f0757974c9af516a [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);
String get invocation {
return '${super.invocation} [project or directory]';
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;