Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Rename option to hideNegatedUsage
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm committed Oct 11, 2024
1 parent 307bda3 commit 9e8664f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/src/allow_anything_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AllowAnythingParser implements ArgParser {
bool negatable = true,
void Function(bool)? callback,
bool hide = false,
bool hideNegatable = false,
bool hideNegatedUsage = false,
List<String> aliases = const []}) {
throw UnsupportedError(
"ArgParser.allowAnything().addFlag() isn't supported.");
Expand Down
16 changes: 8 additions & 8 deletions lib/src/arg_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ class ArgParser {
///
/// If [hide] is `true`, this option won't be included in [usage].
///
/// If [hideNegatable] is `true`, the fact that this flag can be negated will
/// If [hideNegatedUsage] is `true`, the fact that this flag can be negated will
/// not be documented in [usage].
/// It is an error for [hideNegatable] to be `true` if [negatable] is `false`.
/// It is an error for [hideNegatedUsage] to be `true` if [negatable] is `false`.
///
/// If [aliases] is provided, these are used as aliases for [name]. These
/// aliases will not appear as keys in the [options] map.
Expand All @@ -137,7 +137,7 @@ class ArgParser {
bool negatable = true,
void Function(bool)? callback,
bool hide = false,
bool hideNegatable = false,
bool hideNegatedUsage = false,
List<String> aliases = const []}) {
_addOption(
name,
Expand All @@ -151,7 +151,7 @@ class ArgParser {
OptionType.flag,
negatable: negatable,
hide: hide,
hideNegatable: hideNegatable,
hideNegatedUsage: hideNegatedUsage,
aliases: aliases);
}

Expand Down Expand Up @@ -291,7 +291,7 @@ class ArgParser {
bool? splitCommas,
bool mandatory = false,
bool hide = false,
bool hideNegatable = false,
bool hideNegatedUsage = false,
List<String> aliases = const []}) {
var allNames = [name, ...aliases];
if (allNames.any((name) => findByNameOrAlias(name) != null)) {
Expand All @@ -313,9 +313,9 @@ class ArgParser {
'The option $name cannot be mandatory and have a default value.');
}

if (!negatable && hideNegatable) {
if (!negatable && hideNegatedUsage) {
throw ArgumentError(
'The option $name cannot have `hideNegatable` without being negatable.',
'The option $name cannot have `hideNegatedUsage` without being negatable.',
);
}

Expand All @@ -325,7 +325,7 @@ class ArgParser {
splitCommas: splitCommas,
mandatory: mandatory,
hide: hide,
hideNegatable: hideNegatable,
hideNegatedUsage: hideNegatedUsage,
aliases: aliases);
_options[name] = option;
_optionsAndSeparators.add(option);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/option.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Option newOption(
bool? splitCommas,
bool mandatory = false,
bool hide = false,
bool hideNegatable = false,
bool hideNegatedUsage = false,
List<String> aliases = const []}) {
return Option._(name, abbr, help, valueHelp, allowed, allowedHelp, defaultsTo,
callback, type,
negatable: negatable,
splitCommas: splitCommas,
mandatory: mandatory,
hide: hide,
hideNegatable: hideNegatable,
hideNegatedUsage: hideNegatedUsage,
aliases: aliases);
}

Expand Down Expand Up @@ -71,7 +71,7 @@ class Option {
/// Whether to document that this flag is [negatable].
///
/// This is `null` unless [type] is [OptionType.flag].
final bool? hideNegatable;
final bool? hideNegatedUsage;

/// The callback to invoke with the option's value when the option is parsed.
final Function? callback;
Expand Down Expand Up @@ -115,7 +115,7 @@ class Option {
bool? splitCommas,
this.mandatory = false,
this.hide = false,
this.hideNegatable,
this.hideNegatedUsage,
this.aliases = const []})
: allowed = allowed == null ? null : List.unmodifiable(allowed),
allowedHelp =
Expand Down
2 changes: 1 addition & 1 deletion lib/src/usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class _Usage {

String _longOption(Option option) {
String result;
if (option.negatable! && !option.hideNegatable!) {
if (option.negatable! && !option.hideNegatedUsage!) {
result = '--[no-]${option.name}';
} else {
result = '--${option.name}';
Expand Down
5 changes: 3 additions & 2 deletions test/usage_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ void main() {
''');
});

test('negatable flags with hideNegatable don\'t show "no-" in title', () {
test('negatable flags with hideNegatedUsage don\'t show "no-" in title',
() {
var parser = ArgParser();
parser.addFlag('mode', help: 'The mode', hideNegatable: true);
parser.addFlag('mode', help: 'The mode', hideNegatedUsage: true);

validateUsage(parser, '''
--mode The mode
Expand Down

0 comments on commit 9e8664f

Please sign in to comment.