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
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:very_good_analysis/analysis_options.7.0.0.yaml
include: package:very_good_analysis/analysis_options.yaml
2 changes: 1 addition & 1 deletion example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:very_good_analysis/analysis_options.7.0.0.yaml
include: package:very_good_analysis/analysis_options.yaml
linter:
rules:
public_member_api_docs: false
6 changes: 4 additions & 2 deletions example/bin/example_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Future<void> main(List<String> args) async {
/// exited already. This is useful to prevent Future chains from proceeding
/// after you've decided to exit.
Future<void> _flushThenExit(int status) {
return Future.wait<void>([stdout.close(), stderr.close()])
.then<void>((_) => exit(status));
return Future.wait<void>([
stdout.close(),
stderr.close(),
]).then<void>((_) => exit(status));
}
4 changes: 2 additions & 2 deletions example/lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ExampleCommandRunner extends CompletionCommandRunner<int> {
/// {@macro example_command_runner}
ExampleCommandRunner({
Logger? logger,
}) : _logger = logger ?? Logger(),
super(executableName, description) {
}) : _logger = logger ?? Logger(),
super(executableName, description) {
// Add root options and flags
argParser
..addFlag(
Expand Down
9 changes: 5 additions & 4 deletions example/lib/src/commands/some_commmand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class SomeCommand extends Command<int> {
)
..addOption(
'no-option',
help: 'An option that starts with "no" just to make confusion '
help:
'An option that starts with "no" just to make confusion '
'with negated flags',
)
..addMultiOption(
Expand Down Expand Up @@ -95,9 +96,9 @@ class SomeCommand extends Command<int> {

@override
List<String> get aliases => [
'disguised:some_commmand',
'melon',
];
'disguised:some_commmand',
'melon',
];

@override
Future<int> run() async {
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 0.0.1
publish_to: none

environment:
sdk: ^3.5.0
sdk: ^3.8.1

dependencies:
args: ^2.5.0
Expand All @@ -15,7 +15,7 @@ dependencies:
dev_dependencies:
mocktail: ^1.0.4
test: ^1.25.8
very_good_analysis: ^7.0.0
very_good_analysis: ^9.0.0

executables:
example_cli:
69 changes: 37 additions & 32 deletions example/test/integration/completion_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void main() {
'--continuous': r'A continuous option\: any value is allowed',
'--no-option':
'An option that starts with "no" just to make confusion with negated '
'flags',
'flags',
'--multi-d': 'An discrete option that can be passed multiple times ',
'--multi-c': 'An continuous option that can be passed multiple times',
'--flag': null,
Expand Down Expand Up @@ -313,7 +313,7 @@ void main() {
suggests({
'--no-option':
'An option that starts with "no" just to make confusion with '
'negated flags',
'negated flags',
'--no-flag': null,
'--no-inverseflag': 'A flag that the default value is true',
}),
Expand Down Expand Up @@ -410,13 +410,14 @@ void main() {
});

test(
'**do not** suggest possible options when using equals/quote syntax',
() async {
await expectLater(
'example_cli some_command --discrete="',
suggests(noSuggestions),
);
});
'**do not** suggest possible options when using equals/quote syntax',
() async {
await expectLater(
'example_cli some_command --discrete="',
suggests(noSuggestions),
);
},
);
});

group('discrete (aliases)', () {
Expand All @@ -431,17 +432,19 @@ void main() {
);
});

test('suggest matching options for alias option when typed 2',
() async {
await expectLater(
'example_cli some_command --defined-values ',
suggests({
'foo': 'foo help',
'bar': 'bar help',
'faa': 'faa help',
}),
);
});
test(
'suggest matching options for alias option when typed 2',
() async {
await expectLater(
'example_cli some_command --defined-values ',
suggests({
'foo': 'foo help',
'bar': 'bar help',
'faa': 'faa help',
}),
);
},
);
});

group('continuous', () {
Expand Down Expand Up @@ -634,18 +637,20 @@ void main() {
tags: 'known-issues',
);

test('include discrete multi option value after it is specified',
() async {
await expectLater(
'example_cli some_command --multi-d bar -m ',
suggests({
'fii': 'fii help',
'bar': 'bar help',
'fee': 'fee help',
'i have space': 'an allowed option with space on it',
}),
);
});
test(
'include discrete multi option value after it is specified',
() async {
await expectLater(
'example_cli some_command --multi-d bar -m ',
suggests({
'fii': 'fii help',
'bar': 'bar help',
'fee': 'fee help',
'i have space': 'an allowed option with space on it',
}),
);
},
);
});
});
});
Expand Down
8 changes: 4 additions & 4 deletions example/test/integration/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class CliCompletionMatcher extends CustomMatcher {
Map<String, String?> suggestions, {
this.cursorIndex,
}) : super(
'Completes with the expected suggestions',
'suggestions',
completion(suggestions),
);
'Completes with the expected suggestions',
'suggestions',
completion(suggestions),
);

final int? cursorIndex;

Expand Down
5 changes: 3 additions & 2 deletions example/test/src/commands/some_other_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ void main() {

expect(exitCode, ExitCode.success.code);

verify(() => logger.info('A sub command of some_other_command'))
.called(1);
verify(
() => logger.info('A sub command of some_other_command'),
).called(1);
verify(() => logger.info(' - anything')).called(1);
verify(() => logger.info(' - after')).called(1);
verify(() => logger.info(' - command')).called(1);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/command_runner/completion_command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class CompletionCommandRunner<T> extends CommandRunner<T> {
}

/// The list of commands that should not trigger the auto installation.
static const _reservedCommands = {
static const Set<String> _reservedCommands = {
HandleCompletionRequestCommand.commandName,
InstallCompletionFilesCommand.commandName,
UnistallCompletionFilesCommand.commandName,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/installer/completion_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:meta/meta.dart';
///
/// The map and its content are unmodifiable. This is to ensure that
/// [CompletionConfiguration]s is fully immutable.
typedef ShellCommandsMap
= UnmodifiableMapView<SystemShell, UnmodifiableSetView<String>>;
typedef ShellCommandsMap =
UnmodifiableMapView<SystemShell, UnmodifiableSetView<String>>;

/// {@template completion_configuration}
/// A configuration that stores information on how to handle command
Expand All @@ -28,8 +28,8 @@ class CompletionConfiguration {
/// Creates an empty [CompletionConfiguration].
@visibleForTesting
CompletionConfiguration.empty()
: uninstalls = ShellCommandsMap({}),
installs = ShellCommandsMap({});
: uninstalls = ShellCommandsMap({}),
installs = ShellCommandsMap({});

/// Creates a [CompletionConfiguration] from the given [file] content.
///
Expand Down
19 changes: 12 additions & 7 deletions lib/src/installer/completion_installation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ class CompletionInstallation {
_logSourceInstructions(rootCommand);
}

final completionConfiguration =
CompletionConfiguration.fromFile(completionConfigurationFile);
final completionConfiguration = CompletionConfiguration.fromFile(
completionConfigurationFile,
);
completionConfiguration
.copyWith(
uninstalls: completionConfiguration.uninstalls.exclude(
Expand Down Expand Up @@ -305,7 +306,8 @@ class CompletionInstallation {
_sourceScriptOnFile(
configFile: shellRCFile,
scriptName: 'Completion',
description: 'Completion scripts setup. '
description:
'Completion scripts setup. '
'Remove the following line to uninstall',
scriptPath: path.join(
completionConfigDir.path,
Expand Down Expand Up @@ -344,7 +346,8 @@ class CompletionInstallation {

description ??= 'Completion config for "$scriptName"';

final content = '''
final content =
'''
## $description
${configuration!.sourceLineTemplate(scriptPath)}''';
ScriptConfigurationEntry(scriptName).appendTo(
Expand Down Expand Up @@ -429,14 +432,16 @@ ${configuration!.sourceLineTemplate(scriptPath)}''';
completionEntry.removeFrom(shellRCFile);
}
final completionConfigDirContent = completionConfigDir.listSync();
final onlyHasConfigurationFile = completionConfigDirContent.length == 1 &&
final onlyHasConfigurationFile =
completionConfigDirContent.length == 1 &&
path.absolute(completionConfigDirContent.first.path) ==
path.absolute(completionConfigurationFile.path);
if (completionConfigDirContent.isEmpty || onlyHasConfigurationFile) {
completionConfigDir.deleteSync(recursive: true);
} else {
final completionConfiguration =
CompletionConfiguration.fromFile(completionConfigurationFile);
final completionConfiguration = CompletionConfiguration.fromFile(
completionConfigurationFile,
);
completionConfiguration
.copyWith(
uninstalls: completionConfiguration.uninstalls.include(
Expand Down
3 changes: 2 additions & 1 deletion lib/src/installer/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class CompletionInstallationException implements Exception {
final String rootCommand;

@override
String toString() => 'Could not install completion scripts for $rootCommand: '
String toString() =>
'Could not install completion scripts for $rootCommand: '
'$message';
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/installer/script_configuration_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'dart:io';
class ScriptConfigurationEntry {
/// {@macro script_entry}
const ScriptConfigurationEntry(this.name)
: _startComment = '## [$name]',
_endComment = '## [/$name]';
: _startComment = '## [$name]',
_endComment = '## [/$name]';

/// The name of the entry.
final String name;
Expand Down
5 changes: 3 additions & 2 deletions lib/src/parser/arg_parser_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ extension ArgParserExtension on ArgParser {
});

try {
return commandsOnlyGrammar
.parse(filteredArgs.where((element) => element.isNotEmpty));
return commandsOnlyGrammar.parse(
filteredArgs.where((element) => element.isNotEmpty),
);
} on ArgParserException {
return null;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/src/parser/completion_level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,18 @@ class CompletionLevel {
// rawArgs should be only the args after the last parsed command
final List<String> rawArgs;
if (commandName != null) {
rawArgs =
rootArgs.skipWhile((value) => value != commandName).skip(1).toList();
rawArgs = rootArgs
.skipWhile((value) => value != commandName)
.skip(1)
.toList();
} else {
rawArgs = rootArgs.toList();
}

final validOptionsResult = originalGrammar.findValidOptions(rawArgs);

final visibleSubcommands = subcommands?.values.where((command) {
final visibleSubcommands =
subcommands?.values.where((command) {
return !command.hidden;
}).toList() ??
[];
Expand Down
8 changes: 4 additions & 4 deletions lib/src/parser/completion_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ class OptionValuesCompletionResult extends CompletionResult {
required this.completionLevel,
required this.optionName,
this.pattern,
}) : isAbbr = false,
includeAbbrName = false;
}) : isAbbr = false,
includeAbbrName = false;

/// {@macro option_values_completion_result}
const OptionValuesCompletionResult.abbr({
required this.completionLevel,
required String abbrName,
this.pattern,
this.includeAbbrName = false,
}) : isAbbr = true,
optionName = abbrName;
}) : isAbbr = true,
optionName = abbrName;

/// The [CompletionLevel] in which the suggested option is supposed to be
/// located at.
Expand Down
5 changes: 3 additions & 2 deletions lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ class CompletionParser {
// option with "allowed" values
// e.g. `my_cli --option valueNam|` or `my_cli -o valueNam|`
if (nonEmptyArgs.length > 1) {
final secondLastNonEmpty =
nonEmptyArgs.elementAt(nonEmptyArgs.length - 2);
final secondLastNonEmpty = nonEmptyArgs.elementAt(
nonEmptyArgs.length - 2,
);

final resultForValues = _getOptionValues(secondLastNonEmpty, argOnCursor);

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ screenshots:
path: doc/screen.png

environment:
sdk: ^3.5.0
sdk: ^3.8.1

dependencies:
args: ^2.5.0
Expand All @@ -21,4 +21,4 @@ dependencies:
dev_dependencies:
mocktail: ^1.0.4
test: ^1.25.8
very_good_analysis: ^7.0.0
very_good_analysis: ^9.0.0
Loading