Change --disable-dds to --no-dds to avoid double negatives (#80900)

Also, refactor internal code to do the same.

See https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#avoid-double-negatives-in-apis
This commit is contained in:
Ian Hickson
2021-04-23 16:29:38 -07:00
committed by GitHub
parent 7ec7d4dae6
commit e5414695d4
16 changed files with 132 additions and 41 deletions

View File

@@ -370,18 +370,46 @@ abstract class FlutterCommand extends Command<void> {
'Specifying port 0 (the default) will find a random free port.'
);
argParser.addFlag(
'disable-dds', // TODO(ianh): this should be called `dds` and default to true (see style guide about double negatives)
'dds',
hide: !verboseHelp,
help: 'Disable the Dart Developer Service (DDS). This flag should only be provided '
'when attaching to an application with an existing DDS instance (e.g., '
'attaching to an application currently connected to by "flutter run") or '
'when running certain tests.\n'
'Passing this flag may degrade IDE functionality if a DDS instance is not '
'already connected to the target application.'
defaultsTo: true,
help: 'Enable the Dart Developer Service (DDS).\n'
'It may be necessary to disable this when attaching to an application with '
'an existing DDS instance (e.g., attaching to an application currently '
'connected to by "flutter run"), or when running certain tests.\n'
'Disabling this feature may degrade IDE functionality if a DDS instance is '
'not already connected to the target application.'
);
argParser.addFlag(
'disable-dds',
hide: !verboseHelp,
help: '(deprecated; use "--no-dds" instead) '
'Disable the Dart Developer Service (DDS).'
);
}
bool get disableDds => boolArg('disable-dds');
bool _ddsEnabled;
bool get enableDds {
if (_ddsEnabled == null) {
if (argResults.wasParsed('disable-dds')) {
if (argResults.wasParsed('dds')) {
throwToolExit('The "--[no-]dds" and "--[no-]disable-dds" arguments are mutually exclusive. Only specify "--[no-]dds".');
}
_ddsEnabled = !boolArg('disable-dds');
// TODO(ianh): enable the following code once google3 is migrated away from --disable-dds (and add test to flutter_command_test.dart)
if (false) { // ignore: dead_code
if (_ddsEnabled) {
globals.printError('${globals.logger.terminal.warningMark} The "--no-disable-dds" argument is deprecated and redundant, and should be omitted.');
} else {
globals.printError('${globals.logger.terminal.warningMark} The "--disable-dds" argument is deprecated. Use "--no-dds" instead.');
}
}
} else {
_ddsEnabled = boolArg('dds');
}
}
return _ddsEnabled;
}
bool get _hostVmServicePortProvided => argResults.wasParsed('observatory-port') ||
argResults.wasParsed('host-vmservice-port');
@@ -435,7 +463,7 @@ abstract class FlutterCommand extends Command<void> {
// If DDS is enabled and no explicit DDS port is provided, use the
// host-vmservice-port for DDS instead and bind the VM service to a random
// port.
if (!disableDds && !argResults.wasParsed('dds-port')) {
if (enableDds && !argResults.wasParsed('dds-port')) {
return null;
}
return _tryParseHostVmservicePort();
@@ -457,11 +485,12 @@ abstract class FlutterCommand extends Command<void> {
void addPublishPort({ bool enabledByDefault = true, bool verboseHelp = false }) {
argParser.addFlag('publish-port',
negatable: true,
hide: !verboseHelp,
help: 'Publish the VM service port over mDNS. Disable to prevent the '
'local network permission app dialog in debug and profile build modes (iOS devices only.)',
defaultsTo: enabledByDefault);
negatable: true,
hide: !verboseHelp,
help: 'Publish the VM service port over mDNS. Disable to prevent the '
'local network permission app dialog in debug and profile build modes (iOS devices only).',
defaultsTo: enabledByDefault,
);
}
bool get disablePortPublication => !boolArg('publish-port');
@@ -1068,11 +1097,13 @@ abstract class FlutterCommand extends Command<void> {
void _printDeprecationWarning() {
if (deprecated) {
globals.printStatus('${globals.logger.terminal.warningMark} The "$name" command is deprecated and '
'will be removed in a future version of Flutter. '
'See https://flutter.dev/docs/development/tools/sdk/releases '
'for previous releases of Flutter.');
globals.printStatus('');
globals.printError(
'${globals.logger.terminal.warningMark} The "$name" command is deprecated and '
'will be removed in a future version of Flutter. '
'See https://flutter.dev/docs/development/tools/sdk/releases '
'for previous releases of Flutter.',
);
globals.printError('');
}
}