-
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.
Merge pull request #152 from yumemi-inc/improve/remove-args-package
Change to be independent of the args package
- Loading branch information
Showing
4 changed files
with
27 additions
and
27 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
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
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,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); | ||
} | ||
} |
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