-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
403: Chore: fix linting issues r=curquiza a=Strift # Pull Request Fixes linting issues blocking #402 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Strift <lau.cazanove@gmail.com>
- Loading branch information
Showing
10 changed files
with
178 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export 'package:meili_tool/src/main.dart'; | ||
import 'package:meili_tool/src/main.dart' as meili; | ||
|
||
void main(List<String> args) async { | ||
await meili.main(args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,19 @@ | ||
import 'package:args/command_runner.dart'; | ||
import 'package:file/file.dart'; | ||
import 'package:meili_tool/src/result.dart'; | ||
import 'package:platform/platform.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'result.dart'; | ||
|
||
abstract class MeiliCommandBase extends Command<PackageResult> { | ||
final Directory packageDirectory; | ||
/// Base class for package commands. | ||
abstract class PackageCommand extends Command<PackageResult> { | ||
@override | ||
final String name; | ||
|
||
MeiliCommandBase( | ||
this.packageDirectory, { | ||
this.platform = const LocalPlatform(), | ||
}); | ||
|
||
/// The current platform. | ||
/// | ||
/// This can be overridden for testing. | ||
final Platform platform; | ||
@override | ||
final String description; | ||
|
||
/// A context that matches the default for [platform]. | ||
p.Context get path => platform.isWindows ? p.windows : p.posix; | ||
// Returns the relative path from [from] to [entity] in Posix style. | ||
/// | ||
/// This should be used when, for example, printing package-relative paths in | ||
/// status or error messages. | ||
String getRelativePosixPath( | ||
FileSystemEntity entity, { | ||
required Directory from, | ||
}) => | ||
p.posix.joinAll(path.split(path.relative(entity.path, from: from.path))); | ||
|
||
String get indentation => ' '; | ||
PackageCommand({ | ||
required this.name, | ||
required this.description, | ||
}); | ||
|
||
bool getBoolArg(String key) { | ||
return (argResults![key] as bool?) ?? false; | ||
} | ||
@override | ||
Future<PackageResult> run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,38 @@ | ||
import 'dart:io' as io; | ||
import 'dart:io'; | ||
|
||
import 'package:args/command_runner.dart'; | ||
import 'package:file/file.dart'; | ||
import 'package:file/local.dart'; | ||
import 'package:meili_tool/src/output_utils.dart'; | ||
import 'package:meili_tool/src/result.dart'; | ||
|
||
import 'core.dart'; | ||
import 'output_utils.dart'; | ||
import 'result.dart'; | ||
import 'update_samples_command.dart'; | ||
|
||
void main(List<String> arguments) { | ||
const FileSystem fileSystem = LocalFileSystem(); | ||
final Directory scriptDir = | ||
fileSystem.file(io.Platform.script.toFilePath()).parent; | ||
final Directory toolsDir = | ||
scriptDir.basename == 'bin' ? scriptDir.parent : scriptDir.parent.parent; | ||
|
||
final Directory meilisearchDirectory = toolsDir.parent; | ||
Future<void> main(List<String> args) async { | ||
final runner = CommandRunner<PackageResult>( | ||
'meili', | ||
'Tool for managing Meilisearch Dart SDK.', | ||
); | ||
|
||
final commandRunner = CommandRunner<PackageResult>( | ||
'dart run ./tool/bin/meili.dart', 'Productivity utils for meilisearch.') | ||
..addCommand(UpdateSamplesCommand(meilisearchDirectory)); | ||
runner.addCommand(UpdateSamplesCommand()); | ||
|
||
commandRunner.run(arguments).then((value) { | ||
if (value == null) { | ||
print('MUST output either a success or fail.'); | ||
assert(false); | ||
io.exit(255); | ||
try { | ||
final result = await runner.run(args); | ||
if (result == null) { | ||
// help command or similar was run | ||
exit(0); | ||
} | ||
switch (value.state) { | ||
case RunState.succeeded: | ||
printSuccess('Success!'); | ||
break; | ||
case RunState.failed: | ||
printError('Failed!'); | ||
if (value.details.isNotEmpty) { | ||
printError(value.details.join('\n')); | ||
|
||
switch (result.state) { | ||
case RunState.success: | ||
printSuccess('Command completed successfully'); | ||
exit(0); | ||
case RunState.failure: | ||
printError('Command failed'); | ||
if (result.details.isNotEmpty) { | ||
printError('Details: ${result.details}'); | ||
} | ||
io.exit(255); | ||
} | ||
}).catchError((Object e) { | ||
final ToolExit toolExit = e as ToolExit; | ||
int exitCode = toolExit.exitCode; | ||
// This should never happen; this check is here to guarantee that a ToolExit | ||
// never accidentally has code 0 thus causing CI to pass. | ||
if (exitCode == 0) { | ||
assert(false); | ||
exitCode = 255; | ||
exit(1); | ||
} | ||
io.exit(exitCode); | ||
}, test: (Object e) => e is ToolExit); | ||
} catch (e, stack) { | ||
printError('Unexpected error: $e\n$stack'); | ||
exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
/// Possible outcomes of a command run for a package. | ||
enum RunState { | ||
/// The command succeeded for the package. | ||
succeeded, | ||
success, | ||
|
||
/// The command failed for the package. | ||
failed, | ||
failure, | ||
} | ||
|
||
/// The result of a [runForPackage] call. | ||
class PackageResult { | ||
/// A successful result. | ||
PackageResult.success() : this._(RunState.succeeded); | ||
PackageResult.success() : this._(RunState.success, []); | ||
|
||
/// A run that failed. | ||
/// | ||
/// If [errors] are provided, they will be listed in the summary, otherwise | ||
/// If [details] are provided, they will be listed in the summary, otherwise | ||
/// the summary will simply show that the package failed. | ||
PackageResult.fail([List<String> errors = const <String>[]]) | ||
: this._(RunState.failed, errors); | ||
PackageResult.failure(String detail) : this._(RunState.failure, [detail]); | ||
|
||
const PackageResult._(this.state, [this.details = const <String>[]]); | ||
const PackageResult._(this.state, this.details); | ||
|
||
/// The state the package run completed with. | ||
final RunState state; | ||
|
||
/// Information about the result: | ||
/// - For `succeeded`, this is empty. | ||
/// - For `skipped`, it contains a single entry describing why the run was | ||
/// skipped. | ||
/// - For `failed`, it contains zero or more specific error details to be | ||
/// - For `success`, this is empty. | ||
/// - For `failure`, it contains zero or more specific error details to be | ||
/// shown in the summary. | ||
final List<String> details; | ||
} |
Oops, something went wrong.