Remove already deprecated APIs (#165)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fcc3229..f6535ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,13 @@
## 2.0.0-nullsafety
+* **BREAKING** Remove APIs that had been marked as deprecated.
+ * `allowMulti` and `splitCommas` arguments to `ArgParser.addOption`, use
+ `ArgParser.addMultiOption`.
+ * `ArgParser.getUsage(),` use `ArgParser.usage`.
+ * `Option.abbreviation`, use `Option.abbr`.
+ * `Option.defaultValue`, use `Option.defaultsTo`.
+ * `OptionType.FLAG/SINGLE/MULTIPLE`, use `OptionType.flag/single/multiple`.
+
## 1.6.0
* Remove `help` from the list of commands in usage.
diff --git a/lib/src/allow_anything_parser.dart b/lib/src/allow_anything_parser.dart
index 16f97fd..64040b8 100644
--- a/lib/src/allow_anything_parser.dart
+++ b/lib/src/allow_anything_parser.dart
@@ -82,9 +82,6 @@
Parser(null, this, Queue.of(args)).parse();
@override
- String getUsage() => usage;
-
- @override
String get usage => '';
@override
diff --git a/lib/src/arg_parser.dart b/lib/src/arg_parser.dart
index 7ccb5b4..6f25efb 100644
--- a/lib/src/arg_parser.dart
+++ b/lib/src/arg_parser.dart
@@ -2,10 +2,6 @@
// 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.
-// TODO(nweiz): Remove this ignore when sdk#30084 is fixed or when args no
-// longer refers to its own deprecated members.
-// ignore_for_file: deprecated_member_use
-
import 'dart:collection';
import 'allow_anything_parser.dart';
@@ -175,16 +171,12 @@
/// that are often surprising, and its use is discouraged in favor of reading
/// values from the [ArgResults].
///
- /// The [allowMultiple] and [splitCommas] options are deprecated; the
- /// [addMultiOption] method should be used instead.
- ///
/// If [hide] is `true`, this option won't be included in [usage].
///
/// Throws an [ArgumentError] if:
///
/// * There is already an option with name [name].
/// * There is already an option using abbreviation [abbr].
- /// * [splitCommas] is passed but [allowMultiple] is `false`.
void addOption(String name,
{String? abbr,
String? help,
@@ -193,27 +185,9 @@
Map<String, String>? allowedHelp,
String? defaultsTo,
Function? callback,
- @Deprecated('Use addMultiOption() instead.') bool allowMultiple = false,
- @Deprecated('Use addMultiOption() instead.') bool? splitCommas,
bool hide = false}) {
- if (!allowMultiple && splitCommas != null) {
- throw ArgumentError(
- 'splitCommas may not be set if allowMultiple is false.');
- }
-
- _addOption(
- name,
- abbr,
- help,
- valueHelp,
- allowed,
- allowedHelp,
- allowMultiple
- ? (defaultsTo == null ? <String>[] : [defaultsTo])
- : defaultsTo,
- callback,
- allowMultiple ? OptionType.multiple : OptionType.single,
- splitCommas: splitCommas,
+ _addOption(name, abbr, help, valueHelp, allowed, allowedHelp, defaultsTo,
+ callback, OptionType.single,
hide: hide);
}
@@ -328,12 +302,6 @@
/// Generates a string displaying usage information for the defined options.
///
/// This is basically the help text shown on the command line.
- @Deprecated('Replaced with get usage. getUsage() will be removed in args 1.0')
- String getUsage() => usage;
-
- /// Generates a string displaying usage information for the defined options.
- ///
- /// This is basically the help text shown on the command line.
String get usage {
return Usage(_optionsAndSeparators, lineLength: usageLineLength).generate();
}
diff --git a/lib/src/option.dart b/lib/src/option.dart
index 958929a..5361f26 100644
--- a/lib/src/option.dart
+++ b/lib/src/option.dart
@@ -37,9 +37,6 @@
/// `-avalue`.
final String? abbr;
- @Deprecated('Use abbr instead.')
- String? get abbreviation => abbr;
-
/// A description of this option.
final String? help;
@@ -55,9 +52,6 @@
/// The value this option will have if the user doesn't explicitly pass it.
final dynamic defaultsTo;
- @Deprecated('Use defaultsTo instead.')
- dynamic get defaultValue => defaultsTo;
-
/// Whether this flag's value can be set to `false`.
///
/// For example, if [name] is `flag`, the user can pass `--no-flag` to set its
@@ -155,9 +149,6 @@
/// The presence of the option name itself in the argument list means `true`.
static const flag = OptionType._('OptionType.flag');
- @Deprecated('Use OptionType.flag instead.')
- static const FLAG = flag; // ignore: constant_identifier_names
-
/// An option that takes a single value.
///
/// Examples:
@@ -169,9 +160,6 @@
/// If the option is passed more than once, the last one wins.
static const single = OptionType._('OptionType.single');
- @Deprecated('Use OptionType.single instead.')
- static const SINGLE = single; // ignore: constant_identifier_names
-
/// An option that allows multiple values.
///
/// Example:
@@ -182,9 +170,6 @@
/// a list, even if one or no values were passed.
static const multiple = OptionType._('OptionType.multiple');
- @Deprecated('Use OptionType.multiple instead.')
- static const MULTIPLE = multiple; // ignore: constant_identifier_names
-
final String name;
const OptionType._(this.name);
diff --git a/test/allow_anything_test.dart b/test/allow_anything_test.dart
index 06a4e13..0ca31bf 100644
--- a/test/allow_anything_test.dart
+++ b/test/allow_anything_test.dart
@@ -21,7 +21,6 @@
expect(parser.allowTrailingOptions, isFalse);
expect(parser.allowsAnything, isTrue);
expect(parser.usage, isEmpty);
- expect(parser.getUsage(), isEmpty); // ignore: deprecated_member_use
expect(parser.findByAbbreviation('a'), isNull);
});
diff --git a/test/args_test.dart b/test/args_test.dart
index f101f90..70ccd78 100644
--- a/test/args_test.dart
+++ b/test/args_test.dart
@@ -110,23 +110,6 @@
}
});
- test(
- 'throws ArgumentError if splitCommas is passed with allowMultiple: '
- 'false', () {
- var parser = ArgParser();
- throwsIllegalArg(() {
- parser.addOption(
- 'flummox', splitCommas: true, // ignore: deprecated_member_use
- );
- });
- throwsIllegalArg(() {
- parser.addOption(
- 'flummox',
- splitCommas: false, // ignore: deprecated_member_use
- );
- });
- });
-
test('accepts valid option names', () {
var parser = ArgParser();
@@ -284,15 +267,6 @@
parser.addFlag('flag-def', defaultsTo: true);
parser.addOption('single-no');
parser.addOption('single-def', defaultsTo: 'def');
- parser.addOption(
- 'allow-multi-no',
- allowMultiple: true, // ignore: deprecated_member_use
- );
- parser.addOption(
- 'allow-multi-def',
- allowMultiple: true, // ignore: deprecated_member_use
- defaultsTo: 'def',
- );
parser.addMultiOption('multi-no');
parser.addMultiOption('multi-def', defaultsTo: ['def']);
@@ -304,13 +278,6 @@
expect(parser.options['single-no']!.getOrDefault('v'), equals('v'));
expect(parser.options['single-def']!.getOrDefault(null), equals('def'));
expect(parser.options['single-def']!.getOrDefault('v'), equals('v'));
- expect(parser.options['allow-multi-no']!.getOrDefault(null), equals([]));
- expect(
- parser.options['allow-multi-no']!.getOrDefault(['v']), equals(['v']));
- expect(parser.options['allow-multi-def']!.getOrDefault(null),
- equals(['def']));
- expect(parser.options['allow-multi-def']!.getOrDefault(['v']),
- equals(['v']));
expect(parser.options['multi-no']!.getOrDefault(null), equals([]));
expect(parser.options['multi-no']!.getOrDefault(['v']), equals(['v']));
expect(parser.options['multi-def']!.getOrDefault(null), equals(['def']));
diff --git a/test/parse_test.dart b/test/parse_test.dart
index 1c50c4a..c54e142 100644
--- a/test/parse_test.dart
+++ b/test/parse_test.dart
@@ -161,108 +161,6 @@
parser.parse([]);
});
- group('with allowMultiple', () {
- test('for multiple present, options are invoked with value as a list',
- () {
- var a;
- var parser = ArgParser();
- parser.addOption('a',
- allowMultiple: true, // ignore: deprecated_member_use
- callback: (value) => a = value);
-
- parser.parse(['--a=v', '--a=x']);
- expect(a, equals(['v', 'x']));
-
- // This reified type is important in strong mode so that people can
- // safely write "as List<String>".
- expect(a, TypeMatcher<List<String>>());
- });
-
- test(
- 'for single present, options are invoked with value as a single '
- 'element list', () {
- var a;
- var parser = ArgParser();
- parser.addOption('a',
- allowMultiple: true, // ignore: deprecated_member_use
- callback: (value) => a = value);
-
- parser.parse(['--a=v']);
- expect(a, equals(['v']));
- });
-
- test('for absent, options are invoked with default value as a list',
- () {
- var a;
- var parser = ArgParser();
- parser.addOption('a',
- allowMultiple: true, // ignore: deprecated_member_use
- defaultsTo: 'v',
- callback: (value) => a = value);
-
- parser.parse([]);
- expect(a, equals(['v']));
- });
-
- test('for absent, options are invoked with value as an empty list', () {
- var a;
- var parser = ArgParser();
- parser.addOption('a',
- allowMultiple: true, // ignore: deprecated_member_use
- callback: (value) => a = value);
-
- parser.parse([]);
- expect(a, isEmpty);
- });
-
- test('parses comma-separated strings', () {
- var a;
- var parser = ArgParser();
- parser.addOption('a',
- allowMultiple: true, // ignore: deprecated_member_use
- callback: (value) => a = value);
-
- parser.parse(['--a=v,w', '--a=x']);
- expect(a, equals(['v', 'w', 'x']));
- });
-
- test("doesn't parse comma-separated strings with splitCommas: false",
- () {
- var a;
- var parser = ArgParser();
- parser.addOption('a',
- allowMultiple: true, // ignore: deprecated_member_use
- splitCommas: false, // ignore: deprecated_member_use
- callback: (value) => a = value);
-
- parser.parse(['--a=v,w', '--a=x']);
- expect(a, equals(['v,w', 'x']));
- });
-
- test('parses empty strings', () {
- var a;
- var parser = ArgParser();
- parser.addOption('a',
- allowMultiple: true, // ignore: deprecated_member_use
- callback: (value) => a = value);
-
- parser.parse(['--a=,v', '--a=w,', '--a=,', '--a=x,,y', '--a', '']);
- expect(a, equals(['', 'v', 'w', '', '', '', 'x', '', 'y', '']));
- });
-
- test('with allowed parses comma-separated strings', () {
- var a;
- var parser = ArgParser();
- parser.addOption('a',
- allowMultiple: true, // ignore: deprecated_member_use
- allowed: ['v', 'w', 'x'],
- callback: (value) => a = value);
-
- parser.parse(['--a=v,w', '--a=x']);
- expect(a, equals(['v', 'w', 'x']));
- });
- });
-
group('with addMultiOption', () {
test('for multiple present, options are invoked with value as a list',
() {
@@ -437,17 +335,6 @@
});
group('throw if a comma-separated value is not allowed', () {
- test('with allowMultiple', () {
- var parser = ArgParser();
- parser.addOption(
- 'mode',
- abbr: 'm', allowMultiple: true, // ignore: deprecated_member_use
- allowed: ['debug', 'release'],
- );
-
- throwsFormat(parser, ['-mdebug,profile']);
- });
-
test('with addMultiOption', () {
var parser = ArgParser();
parser
@@ -559,17 +446,6 @@
});
group('returns a List', () {
- test('with allowMultiple', () {
- var parser = ArgParser();
- parser.addOption(
- 'define', allowMultiple: true, // ignore: deprecated_member_use
- );
- var args = parser.parse(['--define=1']);
- expect(args['define'], equals(['1']));
- args = parser.parse(['--define=1', '--define=2']);
- expect(args['define'], equals(['1', '2']));
- });
-
test('with addMultiOption', () {
var parser = ArgParser();
parser.addMultiOption('define');
@@ -581,17 +457,6 @@
});
group('returns the default value if not explicitly set', () {
- test('with allowMultiple', () {
- var parser = ArgParser();
- parser.addOption(
- 'define',
- defaultsTo: '0',
- allowMultiple: true, // ignore: deprecated_member_use
- );
- var args = parser.parse(['']);
- expect(args['define'], equals(['0']));
- });
-
test('with addMultiOption', () {
var parser = ArgParser();
parser.addMultiOption('define', defaultsTo: ['0']);
diff --git a/test/usage_test.dart b/test/usage_test.dart
index 3b63d45..0ba33f0 100644
--- a/test/usage_test.dart
+++ b/test/usage_test.dart
@@ -107,20 +107,12 @@
help: 'Can be anything', defaultsTo: 'whatevs');
parser.addMultiOption('multiple',
help: 'Can be anything', defaultsTo: ['whatevs']);
- parser.addOption(
- 'allow-multi',
- help: 'Can be anything',
- defaultsTo: 'whatevs',
- allowMultiple: true, // ignore: deprecated_member_use
- );
validateUsage(parser, '''
- --single Can be anything
- (defaults to "whatevs")
- --multiple Can be anything
- (defaults to "whatevs")
- --allow-multi Can be anything
- (defaults to "whatevs")
+ --single Can be anything
+ (defaults to "whatevs")
+ --multiple Can be anything
+ (defaults to "whatevs")
''');
});
@@ -142,16 +134,10 @@
parser.addMultiOption('implicit', help: 'Implicit default');
parser
.addMultiOption('explicit', help: 'Explicit default', defaultsTo: []);
- parser.addOption(
- 'allow-multi',
- help: 'Implicit with allowMultiple',
- allowMultiple: true, // ignore: deprecated_member_use
- );
validateUsage(parser, '''
- --implicit Implicit default
- --explicit Explicit default
- --allow-multi Implicit with allowMultiple
+ --implicit Implicit default
+ --explicit Explicit default
''');
});