Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ class BetterCommandRunner<O extends OptionDefinition, T>
ctx.provider.store(AnalyticsEnabled(analyticsEnabled));
if (analyticsEnabled) {
final actionOption = ctx.specifiedActionOptions().firstOrNull;
final commandName =
actionOption?.option.toString() ??
ctx.next?.command.name ??
ctx.command.name;
final commandName = actionOption is HelpActionOption
? BetterCommandRunnerAnalyticsEvents.help
: actionOption?.option.toString() ??
ctx.next?.command.name ??
ctx.command.name;
return sendAnalyticsEvent(
ctx,
commandName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ void main() {
await flushEventQueue();

expect(events, hasLength(1));
expect(events.first, equals('help'));
expect(
events.first,
equals(BetterCommandRunnerAnalyticsEvents.help),
);
},
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ void main() {

await Future.delayed(const Duration(milliseconds: 100));
expect(analyticsEvents, hasLength(1));
expect(analyticsEvents.single, 'help');
expect(
analyticsEvents.single,
BetterCommandRunnerAnalyticsEvents.help,
);
});

test('when running with subcommand `help` '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void main() {
'then option name is mandatory message is logged to error.',
() async {
expect(errors, hasLength(1));
expect(errors.first, contains('Option `name` is mandatory'));
expect(errors.first, contains('Option "--name" is mandatory'));
},
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class CompletionCommand<T> extends Command<CompletionOption, T> {
'The script needs to be installed only once: it asks '
'$_executableName for the completion alternatives, so it keeps '
'up automatically when $_executableName is updated.\n\n'
'To install it, run `$_executableName completion install`.\n\n'
'To install it, run "$_executableName completion install".\n\n'
'${completionInstallationOverview(_executableName, heading: 'Manual installation:')}\n\n'
'For a wrapper script with name <name>, generate or install '
'the script with `--command <name>`.',
'the script with "--command <name>".',
hidden: _hidden,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class _ChainParsedArgs implements ParsedArgs {
final value = result.flagOptions[option];
if (value != null) return value;
}
throw StateError('Flag ${option.argName} not found');
throw StateError('Flag $option not found');
}

@override
Expand All @@ -581,7 +581,7 @@ class _ChainParsedArgs implements ParsedArgs {
final value = result.regularOptions[option];
if (value != null && _wasTyped(value)) return value;
}
throw StateError('Option ${option.argName} not found');
throw StateError('Option $option not found');
}

@override
Expand All @@ -594,7 +594,7 @@ class _ChainParsedArgs implements ParsedArgs {
.toList();
}
}
throw StateError('Multi-option ${option.argName} not found');
throw StateError('Multi-option $option not found');
}

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/config/lib/src/config/arg_parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ void _rejectSubcommandSpelling(
final kind = isAlias ? 'alias' : 'name';
throw CommandDefinitionError(
subcommand,
'Subcommand $kind `$spelling` collides with ${option.option.qualifiedString()} '
'Subcommand $kind "$spelling" collides with ${option.option.qualifiedString()} '
'for command $commandName',
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/config/lib/src/config/arg_parser_bridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class OldParsedArgs implements ParsedArgs {
String _optionArgName(final OptionDefinition option) {
final argName = option.option.argName;
if (argName == null) {
throw StateError('Option has no arg name: $option');
throw StateError('Option has no arg name: ${option.option}');
}
return argName;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/config/lib/src/config/arg_parser_facade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class NewParsedArgs implements ParsedArgs {
bool flag(final FlagOption option) {
final value = _result.flagOptions[option];
if (value == null) {
throw StateError('Flag ${option.option.argName} not found');
throw StateError('Flag ${option.option} not found');
}
return value;
}
Expand All @@ -110,7 +110,7 @@ class NewParsedArgs implements ParsedArgs {
String option(final OptionDefinition option) {
final value = _result.regularOptions[option];
if (value == null) {
throw StateError('Option ${option.option.argName} not found');
throw StateError('Option ${option.option} not found');
}
return value;
}
Expand All @@ -119,7 +119,7 @@ class NewParsedArgs implements ParsedArgs {
List<String> multiOption(final MultiOption option) {
final value = _result.multiOptions[option];
if (value == null) {
throw StateError('Multi-option ${option.option.argName} not found');
throw StateError('Multi-option ${option.option} not found');
}
return value;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/config/lib/src/config/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CommandDefinitionError extends ConfigDefinitionError {

@override
String toString() {
final label = 'command `${command.name}`';
final label = 'command "${command.name}"';
return message != null
? '$runtimeType: Invalid definition for $label: $message'
: '$runtimeType: Invalid definition for $label';
Expand Down
31 changes: 18 additions & 13 deletions packages/config/lib/src/config/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,26 @@ abstract class ConfigOptionBase<V> implements OptionDefinition<V> {
];
}

// TODO: Present arg options including the '--' prefix,
// and {position 0} for positional arguments without a name.
@override
String toString() => argName ?? envName ?? '<unnamed option>';
String toString() => _argString ?? envName ?? _unnamedOptionString;

String? get _argString => argName != null
? '--$argName'
: argPos != null
? '{$argPos}'
: null;

String qualifiedString() {
if (argName != null) {
return V is bool ? 'flag `$argName`' : 'option `$argName`';
final kind = this is ConfigOptionBase<bool> ? 'flag' : 'option';
return '$kind "--$argName"';
}
if (argPos != null) {
return 'positional argument {$argPos}';
}
if (envName != null) {
return 'environment variable `$envName`';
}
if (argPos != null) {
return 'positional argument $argPos';
}
final keys = allConfigKeys;
if (keys.isNotEmpty) {
if (keys.length == 1) {
Expand Down Expand Up @@ -914,7 +919,7 @@ List<OptionDefinition> validateOptions(
if (argPosOpts.containsKey(opt.option.argPos)) {
throw OptionDefinitionError(
opt,
'Duplicate argument position: ${opt.option.argPos} for $opt',
'Duplicate argument position: ${opt.option.argPos} for ${opt.option}',
);
}
argPosOpts[argPos] = opt;
Expand All @@ -925,7 +930,7 @@ List<OptionDefinition> validateOptions(
if (envNameOpts.containsKey(opt.option.envName)) {
throw OptionDefinitionError(
opt,
'Duplicate environment variable name: ${opt.option.envName} for $opt',
'Duplicate environment variable name: ${opt.option.envName} for ${opt.option}',
);
}
envNameOpts[envName] = opt;
Expand Down Expand Up @@ -980,15 +985,15 @@ void _claimOptionArgs(
names,
argName,
opt,
'Duplicate argument name: $argName for $opt',
'Duplicate argument name: "$argName" of ${opt.option}',
);
if (opt.option case final FlagOption flag when flag.negatable) {
final negation = 'no-$argName';
_claimArg(
names,
negation,
opt,
'Duplicate argument name: $negation for $opt',
'Duplicate argument name: "$negation" of ${opt.option}',
);
}

Expand All @@ -998,7 +1003,7 @@ void _claimOptionArgs(
names,
alias,
opt,
'Duplicate argument name: $alias for $opt',
'Duplicate argument name: alias "$alias" of ${opt.option}',
);
}
}
Expand All @@ -1008,7 +1013,7 @@ void _claimOptionArgs(
abbrevs,
abbrev,
opt,
'Duplicate argument abbreviation: $abbrev for $opt',
'Duplicate argument abbreviation: "$abbrev" of ${opt.option}',
);
}
}
Expand Down
18 changes: 9 additions & 9 deletions packages/config/test/command/command_run_context_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void main() {
});

test('when the option is omitted then the missing option is reported', () {
expect(error?.message, 'greet: Option `name` is mandatory.');
expect(error?.message, 'greet: Option "--name" is mandatory.');
});

test(
Expand Down Expand Up @@ -253,7 +253,7 @@ void main() {
expect(
error?.message,
'greet: Unknown option: --missing.\n'
'greet: Option `name` is mandatory.',
'greet: Option "--name" is mandatory.',
);
},
);
Expand Down Expand Up @@ -288,8 +288,8 @@ void main() {
test('when both options are omitted then both errors are reported', () {
expect(
error?.message,
'greet: Option `name` is mandatory.\n'
'greet: Option `target` is mandatory.',
'greet: Option "--name" is mandatory.\n'
'greet: Option "--target" is mandatory.',
);
});
});
Expand Down Expand Up @@ -343,8 +343,8 @@ void main() {
() {
expect(
error?.message,
'tool: Option `verbose` is mandatory.\n'
'greet: Option `name` is mandatory.',
'tool: Option "--verbose" is mandatory.\n'
'greet: Option "--name" is mandatory.',
);
},
);
Expand Down Expand Up @@ -789,8 +789,8 @@ void main() {
test('when the variable is not allowed then the value is reported', () {
expect(
error?.message,
'greet: Invalid value for option `user`: '
'`nope` is not an allowed value for option `user`.',
'greet: Invalid value for option "--user": '
'`nope` is not an allowed value for option "--user"',
);
});

Expand Down Expand Up @@ -883,7 +883,7 @@ void main() {
() {
expect(
error?.message,
'greet: Option `jobs` value true is of type bool, not int.',
'greet: Option "--jobs" value true is of type bool, not int.',
);
},
);
Expand Down
10 changes: 5 additions & 5 deletions packages/config/test/command/command_validation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void main() {
test('then the duplicate command name is reported', () {
expect(
error.toString(),
'CommandDefinitionError: Invalid definition for command `build`: '
'CommandDefinitionError: Invalid definition for command "build": '
'Duplicate subcommand name: build for command tool',
);
});
Expand Down Expand Up @@ -138,9 +138,9 @@ void main() {
isA<CommandDefinitionError>().having(
(final error) => error.toString(),
'toString',
'CommandDefinitionError: Invalid definition for command `build`: '
'CommandDefinitionError: Invalid definition for command "build": '
'Cannot define positional options on a command with subcommands: '
'option `file`.',
'option "--file".',
),
);
});
Expand Down Expand Up @@ -200,8 +200,8 @@ void main() {
isA<OptionDefinitionError>().having(
(final error) => error.toString(),
'toString',
'OptionDefinitionError: Invalid definition for option `target`: '
'Duplicate argument name: target for target',
'OptionDefinitionError: Invalid definition for option "--target": '
'Duplicate argument name: "target" of --target',
),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void main() {
'then the install subcommand is described and listed', () async {
await runner.run(['completion', '--help']);
final output = out.toString();
expect(output, contains('run `comptool completion install`'));
expect(output, contains('run "comptool completion install"'));
expect(
output,
matches(RegExp(r'install +Install the shell completion script')),
Expand Down Expand Up @@ -766,7 +766,7 @@ void main() {
'message',
allOf(
contains('Missing value for option: --completion'),
contains('`target` is mandatory'),
contains('"--target" is mandatory'),
),
),
),
Expand All @@ -783,7 +783,7 @@ void main() {
(final e) => e.message,
'message',
allOf(
contains('Invalid value for option `completion`: ""'),
contains('Invalid value for option "--completion": ""'),
contains('bash|zsh|fish|powershell|carapace'),
),
),
Expand All @@ -799,7 +799,7 @@ void main() {
isA<UsageException>().having(
(final e) => e.message,
'message',
contains('Invalid value for option `completion`: "ksh"'),
contains('Invalid value for option "--completion": "ksh"'),
),
),
);
Expand All @@ -814,7 +814,7 @@ void main() {
(final e) => e.message,
'message',
contains(
'Invalid value for option `completion`: "ksh" '
'Invalid value for option "--completion": "ksh" '
'is not in bash|zsh|fish|powershell|carapace',
),
),
Expand All @@ -832,7 +832,7 @@ void main() {
isA<UsageException>().having(
(final e) => e.message,
'message',
contains('Invalid value for option `completion`: "Bash"'),
contains('Invalid value for option "--completion": "Bash"'),
),
),
);
Expand Down
Loading
Loading