Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upgrade of CLI service and some changes #103

Merged
merged 6 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/cli.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library cli;

export 'src/internal/services/cli/command_line_interface.dart' show CommandLineInterface;
6 changes: 3 additions & 3 deletions lib/src/api/channels/guild_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:mineral/core/api.dart';
import 'package:mineral/framework.dart';
import 'package:mineral/src/api/builders/channel_builder.dart';
import 'package:mineral/src/api/managers/permission_overwrite_manager.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_ioc/ioc.dart';

class GuildChannel extends PartialChannel {
Expand Down Expand Up @@ -90,12 +90,12 @@ class GuildChannel extends PartialChannel {

bool _validate () {
if (type == ChannelType.guildCategory) {
ioc.use<MineralCli>().console.warn('A category channel cannot have a parent');
ioc.use<ConsoleService>().warn('A category channel cannot have a parent');
return false;
}

if (type == ChannelType.guildPublicThread || type == ChannelType.private || type == ChannelType.guildNewsThread) {
ioc.use<MineralCli>().console.warn('A thread channel cannot change a parent');
ioc.use<ConsoleService>().warn('A thread channel cannot change a parent');
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/src/api/channels/news_channel.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:mineral/core.dart';
import 'package:mineral/core/api.dart';
import 'package:mineral/src/api/managers/message_manager.dart';
import 'package:mineral/src/api/managers/permission_overwrite_manager.dart';
import 'package:mineral/src/api/managers/thread_manager.dart';
import 'package:mineral/src/api/managers/webhook_manager.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_ioc/ioc.dart';

class NewsChannel extends TextChannel {
Expand All @@ -30,7 +29,7 @@ class NewsChannel extends TextChannel {
/// Follow this by an webhook application
Future<void> follow (Snowflake webhookId) async {
if (type != ChannelType.guildNews) {
ioc.use<MineralCli>().console.warn('Impossible to follow the channel $id as it is not an announcement channel');
ioc.use<ConsoleService>().warn('Impossible to follow the channel $id as it is not an announcement channel');
return;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/api/channels/partial_channel.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:collection/collection.dart';
import 'package:mineral/core/api.dart';
import 'package:mineral/src/api/channels/dm_channel.dart';
import 'package:mineral/src/api/channels/news_channel.dart';
import 'package:mineral/src/api/channels/stage_channel.dart';
import 'package:mineral_console/mineral_console.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_ioc/ioc.dart';

class PartialChannel {
final Snowflake _id;
Expand Down Expand Up @@ -46,7 +46,7 @@ class ChannelWrapper {
final ChannelType? channelType = ChannelType.values.firstWhereOrNull((element) => element.value == payload['type']);

if (channelType == null) {
Console(theme: DefaultTheme()).warn("Guild channel ${payload['type']} don't exist! Please report this to our team.");
ioc.use<ConsoleService>().warn("Guild channel ${payload['type']} don't exist! Please report this to our team.");
return null;
}

Expand All @@ -72,7 +72,7 @@ class ChannelWrapper {
case ChannelType.guildForum:
return ForumChannel.fromPayload(payload);
default:
Console(theme: DefaultTheme()).warn('$channelType is not supported');
ioc.use<ConsoleService>().warn('$channelType is not supported');
}

return null;
Expand Down
4 changes: 0 additions & 4 deletions lib/src/api/channels/text_based_channel.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import 'package:mineral/core/api.dart';
import 'package:mineral/framework.dart';
import 'package:mineral/src/api/builders/channel_builder.dart';
import 'package:mineral/src/api/managers/webhook_manager.dart';
import 'package:mineral_ioc/ioc.dart';
import 'package:mineral/core.dart';
import 'package:mineral_cli/mineral_cli.dart';

class TextBasedChannel extends PartialTextChannel {
final bool _nsfw;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/api/guilds/guild.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'package:mineral/src/api/managers/sticker_manager.dart';
import 'package:mineral/src/api/managers/webhook_manager.dart';
import 'package:mineral/src/api/welcome_screen.dart';
import 'package:mineral/src/helper.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_ioc/ioc.dart';

enum VerificationLevel {
Expand Down Expand Up @@ -304,7 +304,7 @@ class Guild {
MineralClient client = ioc.use<MineralClient>();

if (owner.id != client.user.id) {
ioc.use<MineralCli>().console.error("You cannot change the owner of the server because it does not belong to the ${client.user.username} client.");
ioc.use<ConsoleService>().error("You cannot change the owner of the server because it does not belong to the ${client.user.username} client.");
return;
}

Expand Down Expand Up @@ -626,7 +626,7 @@ class Guild {
for (String element in payload['features']) {
GuildFeature? feature = GuildFeature.values.firstWhereOrNull((feature) => feature.value == element);
if (feature == null) {
ioc.use<MineralCli>().console.warn('Guild feature $element don\'t exist! Please report this to our team.');
ioc.use<ConsoleService>().warn('Guild feature $element don\'t exist! Please report this to our team.');
} else {
features.add(feature);
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/api/interactions/command_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:core';

import 'package:mineral/core/api.dart';
import 'package:mineral/framework.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral_ioc/ioc.dart';

class CommandInteraction extends Interaction {
Expand Down
6 changes: 2 additions & 4 deletions lib/src/api/managers/message_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import 'package:mineral/core/api.dart';
import 'package:mineral/exception.dart';
import 'package:mineral/framework.dart';
import 'package:mineral/src/api/managers/cache_manager.dart';
import 'package:mineral/src/api/messages/dm_message.dart';
import 'package:mineral/src/api/messages/partial_message.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_ioc/ioc.dart';

class MessageManager<T extends PartialMessage> extends CacheManager<T> {
Expand Down Expand Up @@ -111,8 +110,7 @@ class BulkDeleteBuilder<T extends PartialMessage> {
///
Future<void> amount(int amount, {String? reason}) async {
if (amount >= maxMessages || amount <= minMessages) {
return ioc.use<MineralCli>()
.console.error('Provided too few or too many messages to delete. Must provide at least $minMessages and at most $maxMessages messages to delete. Action canceled');
return ioc.use<ConsoleService>().error('Provided too few or too many messages to delete. Must provide at least $minMessages and at most $maxMessages messages to delete. Action canceled');
}

if(_manager.cache.isEmpty || _manager.cache.length < amount) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/api/managers/sticker_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:mineral/framework.dart';
import 'package:mineral/src/api/managers/cache_manager.dart';
import 'package:mineral/src/api/sticker.dart';
import 'package:mineral/src/helper.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_ioc/ioc.dart';

class StickerManager extends CacheManager<Sticker> {
Expand All @@ -34,7 +34,7 @@ class StickerManager extends CacheManager<Sticker> {
return sticker;
}

ioc.use<MineralCli>().console.warn('cancelled ${guild.name} guild does not have the ${GuildFeature.verified} or ${GuildFeature.partnered} feature.');
ioc.use<ConsoleService>().warn('cancelled ${guild.name} guild does not have the ${GuildFeature.verified} or ${GuildFeature.partnered} feature.');
return null;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/api/managers/voice_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:http/http.dart';
import 'package:mineral/core.dart';
import 'package:mineral/core/api.dart';
import 'package:mineral/framework.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_ioc/ioc.dart';

class VoiceManager {
Expand Down Expand Up @@ -49,7 +49,7 @@ class VoiceManager {
return;
}

ioc.use<MineralCli>().console.error('Unable to ${value ? 'mute' : 'unmute'} user #$_memberId');
ioc.use<ConsoleService>().error('Unable to ${value ? 'mute' : 'unmute'} user #$_memberId');
}

/// ### Deafens or not a server member
Expand All @@ -71,7 +71,7 @@ class VoiceManager {
return;
}

ioc.use<MineralCli>().console.error('Unable to ${value ? 'deaf' : 'undeaf'} user #$_memberId');
ioc.use<ConsoleService>().error('Unable to ${value ? 'deaf' : 'undeaf'} user #$_memberId');
}

/// ### Moves a member from one voice channel to another
Expand Down Expand Up @@ -111,7 +111,7 @@ class VoiceManager {
return;
}

ioc.use<MineralCli>().console.error('Unable to move user $_memberId to $channelId');
ioc.use<ConsoleService>().error('Unable to move user $_memberId to $channelId');
}

factory VoiceManager.from(dynamic payload, Snowflake guildId) {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/api/messages/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:mineral/src/api/messages/message_author.dart';
import 'package:mineral/src/api/messages/message_mention.dart';
import 'package:mineral/src/api/messages/message_sticker_item.dart';
import 'package:mineral/src/api/messages/partial_message.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_ioc/ioc.dart';
import 'package:mineral/src/internal/mixins/mineral_client.dart';

Expand Down Expand Up @@ -69,7 +69,7 @@ class Message extends PartialMessage<TextBasedChannel> {

Future<void> crossPost () async {
if (channel.type != ChannelType.guildNews) {
ioc.use<MineralCli>().console.warn('Message $id cannot be cross-posted as it is not in an announcement channel');
ioc.use<ConsoleService>().warn('Message $id cannot be cross-posted as it is not in an announcement channel');
return;
}

Expand All @@ -79,7 +79,7 @@ class Message extends PartialMessage<TextBasedChannel> {

Future<void> pin (Snowflake webhookId) async {
if (isPinned) {
ioc.use<MineralCli>().console.warn('Message $id is already pinned');
ioc.use<ConsoleService>().warn('Message $id is already pinned');
return;
}

Expand All @@ -89,7 +89,7 @@ class Message extends PartialMessage<TextBasedChannel> {

Future<void> unpin () async {
if (!isPinned) {
ioc.use<MineralCli>().console.warn('Message $id isn\'t pinned');
ioc.use<ConsoleService>().warn('Message $id isn\'t pinned');
return;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/api/users/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:mineral/core/builders.dart';
import 'package:mineral/framework.dart';
import 'package:mineral/src/api/users/user_flag.dart';
import 'package:mineral/src/internal/mixins/mineral_client.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_ioc/ioc.dart';

class User {
Expand Down Expand Up @@ -91,7 +91,7 @@ class User {
return message;
}

ioc.use<MineralCli>().console.warn(payload['message']);
ioc.use<ConsoleService>().warn(payload['message']);
return null;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/commands/compile/exe.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:io';

import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral_console/mineral_console.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_contract/mineral_contract.dart';
import 'package:path/path.dart';

class CompileExecutable extends CliCommand {
CompileExecutable(Console console): super(console, 'compile:exe', 'Compile your application to an executable file', []);
class CompileExecutable extends CliCommandContract {
CompileExecutable(ConsoleService console): super(console, 'compile:exe', 'Compile your application to an executable file', []);

@override
Future<void> handle(args) async {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/commands/compile/js.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:io';

import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral_console/mineral_console.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:mineral_contract/mineral_contract.dart';
import 'package:path/path.dart';

class CompileJavascript extends CliCommand {
CompileJavascript(Console console): super(console, 'compile:js', 'Compile your application to an javascript file', []);
class CompileJavascript extends CliCommandContract {
CompileJavascript(ConsoleService console): super(console, 'compile:js', 'Compile your application to an javascript file', []);

@override
Future<void> handle(args) async {
Expand Down
19 changes: 10 additions & 9 deletions lib/src/commands/help.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import 'dart:io';
import 'package:mineral_contract/mineral_contract.dart';
import 'package:tint/tint.dart';

import 'package:collection/collection.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral_console/mineral_console.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';

class Help extends CliCommand {
final MineralCliContract _cli;
Help(Console console, this._cli): super(console, 'help', 'Displays the list of commands', []);
class Help extends CliCommandContract {
final Map<String, CliCommandContract> _commands;
Help(ConsoleService console, this._commands): super(console, 'help', 'Displays the list of commands', []);

@override
Future<void> handle(args) async {
Map<String, List<CliCommand>> commands = {};
Map<String, List<CliCommandContract>> commands = {};

for (final command in _cli.commands.values) {
for (final command in _commands.values) {
final String key = command.name.contains(':')
? command.name.split(':').first
: 'Available commands';
Expand All @@ -25,8 +26,8 @@ class Help extends CliCommand {
}

String display = '';
_cli.commands.values.toList().sort((a, b) => a.arguments.length + b.arguments.length);
int maxArgumentLength = _cli.commands.values.last.arguments.map((argument) => '<$argument>').join('').length;
_commands.values.toList().sort((a, b) => a.arguments.length + b.arguments.length);
int maxArgumentLength = _commands.values.last.arguments.map((argument) => '<$argument>').join('').length;

for (final group in commands.entries.sorted((a, b) => b.key.length.compareTo(a.key.length))) {
display += '${group.key.blue()}\n';
Expand Down
13 changes: 7 additions & 6 deletions lib/src/commands/make/command.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import 'dart:io';
import 'package:mineral_contract/mineral_contract.dart';
import 'package:prompts/prompts.dart' as prompts;

import 'package:mineral/src/commands/templates/command.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral_console/mineral_console.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:path/path.dart';
import 'package:recase/recase.dart';

class MakeCommand extends CliCommand {
MakeCommand(Console console): super(console, 'make:command', 'Create new command file', ['name']);
class MakeCommand extends CliCommandContract {
MakeCommand(ConsoleService console): super(console, 'make:command', 'Create new command file', ['name']);

@override
Future<void> handle(Map args) async {
final placeInRootFolder = Confirm('Would you like to change the location of your ?', defaultValue: false).build();
final placeInRootFolder = prompts.getBool('Would you like to change the location of your ?', defaultsTo: false);

if (!placeInRootFolder) {
final file = File(join(Directory.current.path, 'src', '${ReCase(args['name']).snakeCase}.dart'));
_createFile(file, args);
return;
}

final location = Ask('Where do you want to create your command file ?').build();
final location = prompts.get('Where do you want to create your command file ?');
final file = File(join(Directory.current.path, 'src', location, '${ReCase(args['name']).snakeCase}.dart'));

await _createFile(file, args);
Expand Down
13 changes: 7 additions & 6 deletions lib/src/commands/make/event.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import 'dart:io';
import 'package:mineral_contract/mineral_contract.dart';
import 'package:prompts/prompts.dart' as prompts;

import 'package:mineral/src/commands/templates/event.dart';
import 'package:mineral_cli/mineral_cli.dart';
import 'package:mineral_console/mineral_console.dart';
import 'package:mineral/src/internal/services/console/console_service.dart';
import 'package:path/path.dart';
import 'package:recase/recase.dart';

class MakeEvent extends CliCommand {
MakeEvent(Console console): super(console, 'make:event', 'Create new event file', ['name']);
class MakeEvent extends CliCommandContract {
MakeEvent(ConsoleService console): super(console, 'make:event', 'Create new event file', ['name']);

@override
Future<void> handle(Map args) async {
final placeInRootFolder = Confirm('Would you like to change the location of your ?', defaultValue: false).build();
final placeInRootFolder = prompts.getBool('Would you like to change the location of your ?', defaultsTo: false);

if (!placeInRootFolder) {
final file = File(join(Directory.current.path, 'src', '${ReCase(args['name']).snakeCase}.dart'));
_createFile(file, args);
return;
}

final location = Ask('Where do you want to create your event file ?').build();
final location = prompts.get('Where do you want to create your event file ?');
final file = File(join(Directory.current.path, 'src', location, '${ReCase(args['name']).snakeCase}.dart'));
await _createFile(file, args);
}
Expand Down
Loading