Skip to content

Commit

Permalink
Merge pull request #132 from mineral-dart/feat-implement-logger-service
Browse files Browse the repository at this point in the history
feat: implement logger service
  • Loading branch information
LeadcodeDev authored Sep 7, 2023
2 parents c7ce4db + f8d8181 commit 70a78a1
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/internal/console/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Console
This directory contains the implementation of the mineral command line interface.
2 changes: 2 additions & 0 deletions lib/internal/services/intents/intents.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ class Intents {

/// Creates an [Intents] service with the intents defined in the builder.
factory Intents.builder(Function(IntentBuilder) builder) => Intents._(builder(IntentBuilder()).intents);

int get calculatedValue => _intents.fold(0, (previousValue, element) => previousValue += element.value);
}
30 changes: 30 additions & 0 deletions lib/services/logger/logger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dart:io';

import 'package:mineral/services/logger/logger_contract.dart';
import 'package:tint/tint.dart';

class Logger implements LoggerContract {
@override
void debug(String message) =>
stdout.writeln('${'[ debug ]'.grey()} $message');

@override
void error(String message) =>
stdout.writeln('${'[ error ]'.red()} $message');

@override
void info(String message) =>
stdout.writeln('${'[ info ]'.cyan()} $message');

@override
void log(message) =>
stdout.writeln('[log] $message');

@override
void success(String message) =>
stdout.writeln('${'[ success ]'.green()} $message');

@override
void warning(String message) =>
stdout.writeln('${'[ warning ]'.yellow()} $message');
}
13 changes: 13 additions & 0 deletions lib/services/logger/logger_contract.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abstract interface class LoggerContract {
void log(dynamic message);

void error(String message);

void warning(String message);

void success(String message);

void info(String message);

void debug(String message);
}
8 changes: 8 additions & 0 deletions test/functionals/intent_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ void main () {
final Intents service = Intents.none();
expect(service.intents, isEmpty);
});

test('can create Intent service without intents', () {
final List<Intent> intents = [Intent.guilds, Intent.directMessages];
final Intents service = Intents.only(intents);

expect(service.intents, allOf([hasLength(2), containsAll(intents)]));
expect(service.calculatedValue, equals(4097));
});
}

0 comments on commit 70a78a1

Please sign in to comment.