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 @@ -14,7 +14,7 @@ import 'package:cli_completion/parser.dart';
/// for completions.
class HandleCompletionRequestCommand<T> extends Command<T> {
/// {@macro handle_completion_request_command}
HandleCompletionRequestCommand();
new();

@override
String get description {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:mason_logger/mason_logger.dart';
/// this command logs messages during the installation process.
class InstallCompletionFilesCommand<T> extends Command<T> {
/// {@macro install_completion_command}
InstallCompletionFilesCommand() {
new() {
argParser.addFlag(
'verbose',
abbr: 'v',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'package:cli_completion/cli_completion.dart';
/// {@endtemplate}
class PrintCompletionScriptCommand<T> extends Command<T> {
/// {@macro print_completion_script_command}
PrintCompletionScriptCommand();
new();

@override
String get description {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:mason_logger/mason_logger.dart';
/// {@endtemplate}
class UnistallCompletionFilesCommand<T> extends Command<T> {
/// {@macro uninstall_completion_command}
UnistallCompletionFilesCommand() {
new() {
argParser.addFlag(
'verbose',
abbr: 'v',
Expand Down
4 changes: 2 additions & 2 deletions lib/src/command_runner/completion_command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'package:meta/meta.dart';
/// and install it manually.
abstract class CompletionCommandRunner<T> extends CommandRunner<T> {
/// {@macro completion_command_runner}
CompletionCommandRunner(
new(
super.executableName,
super.description, {
super.usageLineLength,
Expand Down Expand Up @@ -97,7 +97,7 @@ abstract class CompletionCommandRunner<T> extends CommandRunner<T> {
tryInstallCompletionFiles(Level.error);
}

return super.runCommand(topLevelResults);
return await super.runCommand(topLevelResults);
}

/// Tries to install completion files for the current shell.
Expand Down
11 changes: 4 additions & 7 deletions lib/src/installer/completion_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ typedef ShellCommandsMap =
@immutable
class CompletionConfiguration {
/// {@macro completion_configuration}
const CompletionConfiguration._({
required this.uninstalls,
required this.installs,
});
const new _({required this.uninstalls, required this.installs});

/// Creates an empty [CompletionConfiguration].
@visibleForTesting
CompletionConfiguration.empty()
new empty()
: uninstalls = ShellCommandsMap({}),
installs = ShellCommandsMap({});

Expand All @@ -40,7 +37,7 @@ class CompletionConfiguration {
/// file's content. This content is assumed to be a JSON string. The parsing
/// is handled gracefully, so if the JSON is partially or fully invalid, it
/// handles issues without throwing an [Exception].
factory CompletionConfiguration.fromFile(File file) {
factory fromFile(File file) {
if (!file.existsSync()) {
return CompletionConfiguration.empty();
}
Expand All @@ -50,7 +47,7 @@ class CompletionConfiguration {
}

/// Creates a [CompletionConfiguration] from the given JSON string.
factory CompletionConfiguration._fromJson(String json) {
factory _fromJson(String json) {
late final Map<String, dynamic> decodedJson;
try {
decodedJson = jsonDecode(json) as Map<String, dynamic>;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/installer/completion_installation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:path/path.dart' as path;
class CompletionInstallation {
/// {@macro shell_completion_installation}
@visibleForTesting
CompletionInstallation({
new({
required this.configuration,
required this.logger,
required this.isWindows,
Expand All @@ -30,7 +30,7 @@ class CompletionInstallation {
///
/// Pass [environmentOverride] to override the default value of
/// [Platform.environment].
factory CompletionInstallation.fromSystemShell({
factory fromSystemShell({
required SystemShell? systemShell,
required Logger logger,
bool? isWindowsOverride,
Expand Down
10 changes: 2 additions & 8 deletions lib/src/installer/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
/// {@endtemplate}
class CompletionInstallationException implements Exception {
/// {@macro completion_installation_exception}
CompletionInstallationException({
required this.message,
required this.rootCommand,
});
new({required this.message, required this.rootCommand});

/// The error message for this exception
final String message;
Expand All @@ -25,10 +22,7 @@ class CompletionInstallationException implements Exception {
/// {@endtemplate}
class CompletionUninstallationException implements Exception {
/// {@macro completion_unistallation_exception}
CompletionUninstallationException({
required this.message,
required this.rootCommand,
});
new({required this.message, required this.rootCommand});

/// The error message for this exception
final String message;
Expand Down
13 changes: 3 additions & 10 deletions lib/src/installer/script_configuration_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'dart:io';
/// {@endtemplate}
class ScriptConfigurationEntry {
/// {@macro script_entry}
const ScriptConfigurationEntry(this.name)
const new(this.name)
: _startComment = '## [$name]',
_endComment = '## [/$name]';

Expand Down Expand Up @@ -46,10 +46,7 @@ class ScriptConfigurationEntry {
..writeln(_endComment)
..writeln();

file.writeAsStringSync(
stringBuffer.toString(),
mode: FileMode.append,
);
file.writeAsStringSync(stringBuffer.toString(), mode: FileMode.append);
}

/// Removes the entry with [name] from the [file].
Expand All @@ -68,11 +65,7 @@ class ScriptConfigurationEntry {
final stringPattern = '\n$_startComment.*$_endComment\n\n'
.replaceAll('[', r'\[')
.replaceAll(']', r'\]');
final pattern = RegExp(
stringPattern,
multiLine: true,
dotAll: true,
);
final pattern = RegExp(stringPattern, multiLine: true, dotAll: true);
final newContent = content.replaceAllMapped(pattern, (_) => '');
file.writeAsStringSync(newContent);

Expand Down
6 changes: 2 additions & 4 deletions lib/src/installer/shell_completion_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ typedef SourceStringTemplate = String Function(String scriptPath);
@immutable
class ShellCompletionConfiguration {
/// {@macro shell_completion_configuration}
const ShellCompletionConfiguration._({
const new _({
required this.shell,
required this.shellRCFiles,
required this.sourceLineTemplate,
required this.scriptTemplate,
});

/// Creates a [ShellCompletionConfiguration] given the current [SystemShell].
factory ShellCompletionConfiguration.fromSystemShell(
SystemShell systemShell,
) {
factory fromSystemShell(SystemShell systemShell) {
switch (systemShell) {
case SystemShell.zsh:
return zshConfiguration;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parser/completion_level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:meta/meta.dart';
class CompletionLevel {
/// {@macro completion_level}
@visibleForTesting
const CompletionLevel({
const new({
required this.grammar,
required this.rawArgs,
required this.visibleSubcommands,
Expand Down
24 changes: 7 additions & 17 deletions lib/src/parser/completion_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'package:meta/meta.dart';
@immutable
abstract class CompletionResult {
/// {@macro completion_result}
const CompletionResult();
const new();

/// A collection of [MapEntry] with completion suggestions to their
/// descriptions.
Expand All @@ -32,9 +32,7 @@ abstract class CompletionResult {
/// {@endtemplate}
class AllOptionsAndCommandsCompletionResult extends CompletionResult {
/// {@macro all_options_and_commands_completion_result}
const AllOptionsAndCommandsCompletionResult({
required this.completionLevel,
});
const new({required this.completionLevel});

/// The [CompletionLevel] in which the suggested options and subcommands are
/// supposed to be located at.
Expand Down Expand Up @@ -65,9 +63,7 @@ class AllOptionsAndCommandsCompletionResult extends CompletionResult {
/// - [AllOptionsAndCommandsCompletionResult]
class AllAbbrOptionsCompletionResult extends CompletionResult {
/// {@macro all_options_and_commands_completion_result}
const AllAbbrOptionsCompletionResult({
required this.completionLevel,
});
const new({required this.completionLevel});

/// The [CompletionLevel] in which the suggested options and subcommands are
/// supposed to be located at.
Expand All @@ -94,10 +90,7 @@ class AllAbbrOptionsCompletionResult extends CompletionResult {
/// If a command doesnt match the pattern, its aliases are also checked.
class MatchingCommandsCompletionResult extends CompletionResult {
/// {@macro matching_commands_completion_result}
const MatchingCommandsCompletionResult({
required this.completionLevel,
required this.pattern,
});
const new({required this.completionLevel, required this.pattern});

/// The [CompletionLevel] in which the suggested commands are supposed to be
/// located at.
Expand Down Expand Up @@ -133,10 +126,7 @@ class MatchingCommandsCompletionResult extends CompletionResult {
/// If an option does not match the pattern, its aliases will be checked.
class MatchingOptionsCompletionResult extends CompletionResult {
/// {@macro matching_options_completion_result}
const MatchingOptionsCompletionResult({
required this.completionLevel,
required this.pattern,
});
const new({required this.completionLevel, required this.pattern});

/// The [CompletionLevel] in which the suggested options are supposed to be
/// located at.
Expand Down Expand Up @@ -191,15 +181,15 @@ class MatchingOptionsCompletionResult extends CompletionResult {
/// in an abbreviated form.
class OptionValuesCompletionResult extends CompletionResult {
/// {@macro option_values_completion_result}
const OptionValuesCompletionResult({
const new({
required this.completionLevel,
required this.optionName,
this.pattern,
}) : isAbbr = false,
includeAbbrName = false;

/// {@macro option_values_completion_result}
const OptionValuesCompletionResult.abbr({
const new abbr({
required this.completionLevel,
required String abbrName,
this.pattern,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parser/completion_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:meta/meta.dart';
class CompletionState extends Equatable {
/// {@macro completion_state}
@visibleForTesting
const CompletionState({
const new({
required this.cword,
required this.point,
required this.line,
Expand Down
4 changes: 1 addition & 3 deletions lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import 'package:cli_completion/src/parser/arg_parser_extension.dart';
/// {@endtemplate}
class CompletionParser {
/// {@macro completion_parser}
CompletionParser({
required this.completionLevel,
});
new({required this.completionLevel});

/// The [CompletionLevel] to parse.
final CompletionLevel completionLevel;
Expand Down
6 changes: 2 additions & 4 deletions lib/src/system_shell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum SystemShell {
bash('bash');

/// {@macro system_shell}
const SystemShell(this.name);
new(this.name);

/// A descriptive string to identify the shell among others.
final String name;
Expand All @@ -26,9 +26,7 @@ enum SystemShell {
/// [Platform.environment].
///
/// Based on https://stackoverflow.com/a/3327022
static SystemShell? current({
Map<String, String>? environmentOverride,
}) {
static SystemShell? current({Map<String, String>? environmentOverride}) {
final environment = environmentOverride ?? Platform.environment;

// Heuristic: if ZSH_NAME is set, must be zsh
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ dependencies:
dev_dependencies:
mocktail: ^1.0.4
test: ^1.25.8
very_good_analysis: ^10.3.0
very_good_analysis: ^11.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class MockLogger extends Mock implements Logger {}
class MockLogger extends Mock implements Logger;

class _TestCompletionCommandRunner extends CompletionCommandRunner<int> {
_TestCompletionCommandRunner() : super('test', 'Test command runner') {
final subCommand = _TestCommand(
name: 'subcommand',
description: 'level 1',
);
new() : super('test', 'Test command runner') {
final subCommand = _TestCommand(name: 'subcommand', description: 'level 1');
addCommand(subCommand);
final subSubCommand = _TestCommand(
name: 'subsubcommand2',
Expand All @@ -30,10 +27,7 @@ class _TestCompletionCommandRunner extends CompletionCommandRunner<int> {
}

class _TestCommand extends Command<int> {
_TestCommand({
required this.name,
required this.description,
});
new({required this.name, required this.description});

@override
final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import 'package:mason_logger/mason_logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class _MockLogger extends Mock implements Logger {}
class _MockLogger extends Mock implements Logger;

class _MockCompletionInstallation extends Mock
implements CompletionInstallation {}
implements CompletionInstallation;

class _TestCompletionCommandRunner extends CompletionCommandRunner<int> {
_TestCompletionCommandRunner() : super('test', 'Test command runner');
new() : super('test', 'Test command runner');

@override
// Override acceptable for test files
Expand Down Expand Up @@ -68,12 +68,10 @@ void main() {
test('when verbose', () async {
await commandRunner.run(['install-completion-files', '--verbose']);

verify(
() {
return commandRunner.completionInstallationLogger.level =
Level.verbose;
},
).called(1);
verify(() {
return commandRunner.completionInstallationLogger.level =
Level.verbose;
}).called(1);
});
});
});
Expand Down
Loading
Loading