-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Changed to a simple implementation that only accepts the command
- Loading branch information
Showing
2 changed files
with
25 additions
and
26 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
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
17
packages/yumemi_lints/lib/src/commands/update_command.dart
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,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); | ||
} | ||
} |