Skip to content

Commit

Permalink
refactor: make try/catch blocks shorter (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp authored May 10, 2024
1 parent b910c02 commit b34b9e4
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions native_doctor/lib/src/native_doctor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,28 @@ void printUsage(ArgParser argParser, Writer writer) {
void run(List<String> arguments) async {
final writer = AnsiWriter();
final ArgParser argParser = buildParser();
final ArgResults results;
try {
final ArgResults results = argParser.parse(arguments);
results = argParser.parse(arguments);
} on FormatException catch (e) {
// Print usage information if an invalid argument was provided.
writer.printMessage(e.message);
writer.emptyLine();
printUsage(argParser, writer);
exit(1);
}

// Process the parsed arguments.
if (results.wasParsed('help')) {
printUsage(argParser, writer);
return;
}
if (results.wasParsed('version')) {
print('native_doctor version: $version');
return;
}
// Process the parsed arguments.
if (results.wasParsed('help')) {
printUsage(argParser, writer);
return;
}
if (results.wasParsed('version')) {
print('native_doctor version: $version');
return;
}

try {
final options = ToolOptions(
verbose: results.wasParsed('verbose'),
yes: results.wasParsed('yes'),
Expand All @@ -302,11 +311,6 @@ void run(List<String> arguments) async {
} else {
throw ToolError('Project path ${options.path.path} does not exist.');
}
} on FormatException catch (e) {
// Print usage information if an invalid argument was provided.
writer.printMessage(e.message);
writer.emptyLine();
printUsage(argParser, writer);
} on Exception catch (e) {
writer.emptyLine();
writer.printMessage(writer.color(
Expand Down

0 comments on commit b34b9e4

Please sign in to comment.