Skip to content

Commit

Permalink
fix: move alert messages to custom method (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfenrain committed Jul 15, 2022
1 parent fc41f17 commit ec31ed9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:mason/mason.dart';
import 'package:universal_io/io.dart';
import 'package:very_good_cli/src/commands/create/templates/templates.dart';
import 'package:very_good_cli/src/logger_extension.dart';

/// {@template dart_pkg_template}
/// A Dart package template.
Expand All @@ -24,7 +25,7 @@ class DartPkgTemplate extends Template {
void _logSummary(Logger logger) {
logger
..info('\n')
..alert('Created a Very Good Dart Package! 🦄')
..created('Created a Very Good Dart Package! 🦄')
..info('\n');
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:mason/mason.dart';
import 'package:universal_io/io.dart';
import 'package:very_good_cli/src/commands/create/templates/templates.dart';
import 'package:very_good_cli/src/logger_extension.dart';

/// {@template flutter_pkg_template}
/// A Flutter package template.
Expand All @@ -24,7 +25,7 @@ class FlutterPkgTemplate extends Template {
void _logSummary(Logger logger) {
logger
..info('\n')
..alert('Created a Very Good Flutter Package! 🦄')
..created('Created a Very Good Flutter Package! 🦄')
..info('\n');
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:mason/mason.dart';
import 'package:universal_io/io.dart';
import 'package:very_good_cli/src/commands/create/templates/templates.dart';
import 'package:very_good_cli/src/logger_extension.dart';

/// {@template flutter_plugin_template}
/// A Flutter plugin template.
Expand All @@ -24,7 +25,7 @@ class FlutterPluginTemplate extends Template {
void _logSummary(Logger logger) {
logger
..info('\n')
..alert('Created a Very Good Flutter Plugin! 🦄')
..created('Created a Very Good Flutter Plugin! 🦄')
..info('\n');
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:mason/mason.dart';
import 'package:universal_io/io.dart';
import 'package:very_good_cli/src/commands/create/templates/templates.dart';
import 'package:very_good_cli/src/logger_extension.dart';

/// {@template very_good_core_template}
/// A core Flutter app template.
Expand All @@ -24,7 +25,7 @@ class VeryGoodCoreTemplate extends Template {
void _logSummary(Logger logger) {
logger
..info('\n')
..alert('Created a Very Good App! 🦄')
..created('Created a Very Good App! 🦄')
..info('\n')
..info(
lightGray.wrap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';

import 'package:mason_logger/mason_logger.dart';
import 'package:very_good_cli/src/commands/create/templates/templates.dart';
import 'package:very_good_cli/src/logger_extension.dart';

/// {@template dart_cli_template}
/// A Dart CLI application template.
Expand All @@ -25,7 +26,7 @@ class VeryGoodDartCLITemplate extends Template {
void _logSummary(Logger logger) {
logger
..info('\n')
..alert('Created a Very Good Dart CLI application! 🦄')
..created('Created a Very Good Dart CLI application! 🦄')
..info('\n');
}
}
9 changes: 9 additions & 0 deletions lib/src/logger_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:mason_logger/mason_logger.dart';

/// Extension on the Logger class for custom styled logging.
extension LoggerX on Logger {
/// Log a message in the "created" style of the CLI.
void created(String message) {
info(lightCyan.wrap(styleBold.wrap(message)));
}
}
5 changes: 3 additions & 2 deletions test/src/commands/create/create_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:usage/usage_io.dart';
import 'package:very_good_cli/src/command_runner.dart';
import 'package:very_good_cli/src/commands/create/create.dart';
import 'package:very_good_cli/src/commands/create/templates/templates.dart';
import 'package:very_good_cli/src/logger_extension.dart';

import '../../../helpers/helpers.dart';

Expand Down Expand Up @@ -219,7 +220,7 @@ void main() {
verify(
() => logger.progress('Running "flutter packages get" in .tmp'),
).called(1);
verify(() => logger.alert('Created a Very Good App! 🦄')).called(1);
verify(() => logger.created('Created a Very Good App! 🦄')).called(1);
verify(
() => generator.generate(
any(
Expand Down Expand Up @@ -565,7 +566,7 @@ void main() {
verify(
() => logger.progress(getPackagesMsg),
).called(1);
verify(() => logger.alert(expectedLogSummary)).called(1);
verify(() => logger.created(expectedLogSummary)).called(1);
verify(
() => generator.generate(
any(
Expand Down

0 comments on commit ec31ed9

Please sign in to comment.