Skip to content

Commit

Permalink
Merge pull request #152 from yumemi-inc/improve/remove-args-package
Browse files Browse the repository at this point in the history
Change to be independent of the args package
  • Loading branch information
masa-futa authored Jan 27, 2025
2 parents 9cc2a8c + f9e15b7 commit 556a096
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
1 change: 1 addition & 0 deletions packages/yumemi_lints/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Examples of version updates are as follows:
- Changed to be independent of the `pub_semver` package.
- Changed to be independent of the `yaml` package.
- Changed to be independent of the `file` package.
- Changed to be independent of the `args` package.

## 2.2.0

Expand Down
33 changes: 19 additions & 14 deletions packages/yumemi_lints/lib/src/app_command_runner.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import 'package:args/command_runner.dart';
import 'package:yumemi_lints/src/commands/update_command.dart';
import 'package:yumemi_lints/src/models/exit_status.dart';
import 'package:yumemi_lints/src/utils/cli_info.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 UsageException catch (e) {
print(e.message);
print(e.usage);
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.shouldRunCommand(args)) {
return updateCommand.run();
}
return ExitStatus.error;
}
}
17 changes: 7 additions & 10 deletions packages/yumemi_lints/lib/src/commands/update_command.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import 'package:args/command_runner.dart';
import 'package:yumemi_lints/src/command_services/update_command_service.dart';
import 'package:yumemi_lints/src/models/exit_status.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.';

@override
Future<ExitStatus> run() {
Future<ExitStatus> run() async {
const updateCommandService = UpdateCommandService();
return updateCommandService.call();
}

bool shouldRunCommand(Iterable<String> args) {
return args.contains(name);
}
}
3 changes: 0 additions & 3 deletions packages/yumemi_lints/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ repository: https://github.com/yumemi-inc/flutter-yumemi-lints
environment:
sdk: '>=2.17.0 <4.0.0'

dependencies:
args: ^2.3.1

dev_dependencies:
mockito: ^5.3.2
test: ^1.21.4
Expand Down

0 comments on commit 556a096

Please sign in to comment.