Skip to content

Commit

Permalink
fix: Changed to a simple implementation that only accepts the command
Browse files Browse the repository at this point in the history
  • Loading branch information
masa-futa committed Jan 24, 2025
1 parent f028c80 commit 978f66d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
34 changes: 19 additions & 15 deletions packages/yumemi_lints/lib/src/app_command_runner.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import 'package:yumemi_lints/src/commands/update_command.dart';
import 'package:yumemi_lints/src/models/exceptions.dart';
import 'package:yumemi_lints/src/models/exit_status.dart';
import 'package:yumemi_lints/src/utils/cli_info.dart';
import 'package:yumemi_lints/src/utils/command_runner.dart';

/// A command runner for the yumemi_lints
class AppCommandRunner extends CommandRunner<ExitStatus> {
/// Creates a new instance of [AppCommandRunner]
AppCommandRunner() : super(CliInfo.name, CliInfo.description) {
addCommand(UpdateCommand());
}
class AppCommandRunner {
AppCommandRunner();

@override
Future<ExitStatus> run(Iterable<String> args) async {
try {
final argResults = parse(args);
return await runCommand(argResults) ?? ExitStatus.success;
} on ArgParserException catch (e) {
print(e.message);
print(e.commandName);
return ExitStatus.usage;
if (args.isEmpty) {
return ExitStatus.success;
}
final updateExit = await _evaluateUpdateCommand(args);
return updateExit;
} on Exception catch (e) {
print(e);
return ExitStatus.error;
}
}

/// Evaluates [UpdateCommand].
///
/// If [args] contains the `update` command, takes appropriate action.
/// Otherwise, treats as an error.
Future<ExitStatus> _evaluateUpdateCommand(Iterable<String> args) async {
final updateCommand = UpdateCommand();
if (updateCommand.check(args)) {
return await updateCommand.run() ?? ExitStatus.success;
}
return ExitStatus.error;
}
}
17 changes: 6 additions & 11 deletions packages/yumemi_lints/lib/src/commands/update_command.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import 'package:yumemi_lints/src/command_services/update_command_service.dart';
import 'package:yumemi_lints/src/models/command.dart';
import 'package:yumemi_lints/yumemi_lints.dart';

class UpdateCommand extends Command<ExitStatus> {
class UpdateCommand {
UpdateCommand();

@override
String get name => 'update';

@override
String get description => "Automatically update the version of yumemi_lints'"
' recommended.yaml to match the Dart or Flutter version of the project.';
Future<ExitStatus?> run() async {
return ExitStatus.success;
}

@override
Future<ExitStatus> run() {
const updateCommandService = UpdateCommandService();
return updateCommandService.call();
bool check(Iterable<String> args) {
return args.contains(name);
}
}

0 comments on commit 978f66d

Please sign in to comment.