Skip to content

Commit

Permalink
[ Edit ] Added info debug command for seeing the variables while deve…
Browse files Browse the repository at this point in the history
…loping, it should not be shown in the production version.
  • Loading branch information
anasfik committed Oct 5, 2023
1 parent cc9fe33 commit 86b3eb0
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ coverage/
.test_runner.dart

# Android studio and IntelliJ
.idea
.idea

bin/langsync.exe
6 changes: 5 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.8.1

changed the account creation command from `apiKey` to `create` for more consistency.
- Changed the account creation command from `apiKey` to `create` for more consistency.

# 0.8.2

- Added info debug command for seeing the variables while developing, it should not be shown in the production version.
Binary file modified bin/langsync.exe
Binary file not shown.
5 changes: 4 additions & 1 deletion lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import 'package:args/command_runner.dart';
import 'package:cli_completion/cli_completion.dart';
import 'package:langsync/src/commands/commands.dart';
import 'package:langsync/src/commands/config_command/config_command.dart';
import 'package:langsync/src/commands/debug_info/debug_info.dart';
import 'package:langsync/src/commands/start_command/start_command.dart';
import 'package:langsync/src/commands/supported_laungages_command/supported_laungages_command.dart';
import 'package:langsync/src/etc/utils.dart';
import 'package:langsync/src/version.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:pub_updater/pub_updater.dart';
Expand Down Expand Up @@ -49,8 +51,9 @@ class LangsyncCommandRunner extends CompletionCommandRunner<int> {
addCommand(AccountCommand(logger: _logger));
addCommand(ConfigCommand(logger: _logger));
addCommand(SupportedLangsCommand(logger: _logger));
// addCommand(UpdateCommand(logger: _logger, pubUpdater: _pubUpdater));
addCommand(StartCommand(logger: _logger));

if (utils.isDebugMode) addCommand(DebugInfoCommand(logger: _logger));
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/commands/account_command/account_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AccountCommand extends Command<int> {
addSubcommand(AuthCommand(logger: _logger));
addSubcommand(InfoCommand(logger: _logger));
addSubcommand(LogoutCommand(logger: _logger));
addSubcommand(ApiKeyCommand(logger: _logger));
addSubcommand(AccountCreateCommand(logger: _logger));
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:langsync/src/etc/extensions.dart';
import 'package:langsync/src/etc/networking/client.dart';
import 'package:mason_logger/mason_logger.dart';

class ApiKeyCommand extends Command<int> {
ApiKeyCommand({
class AccountCreateCommand extends Command<int> {
AccountCreateCommand({
required this.logger,
});

Expand Down Expand Up @@ -46,10 +46,8 @@ class ApiKeyCommand extends Command<int> {
final apiKeyDoc = await NetClient.instance.createApiKey(userName);

progress.complete('API key created successfully!');
logger.info('\n');

logger
// ..info('Your username: ${apiKeyDoc.username}')
..info('\n')
..success('Your API key: ${apiKeyDoc.apiKey}')
..info('\n')
..warn(
Expand Down
40 changes: 40 additions & 0 deletions lib/src/commands/debug_info/debug_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:async';

import 'package:args/command_runner.dart';
import 'package:langsync/src/etc/utils.dart';
import 'package:langsync/src/version.dart';
import 'package:mason_logger/mason_logger.dart';

class DebugInfoCommand extends Command<int> {
final Logger logger;

DebugInfoCommand({required this.logger});

@override
String get description =>
'show some useful info while debugging, this command is made for devlopemnet and it should not appear on production version';

@override
String get name => 'debug';

@override
Future<int> run() async {
final debugFields = {
'baseUrl': utils.baseUrl,
'langsyncVersion': packageVersion,
};

final asEntriesList = debugFields.entries.toList();

for (int index = 0; index < debugFields.length; index++) {
final current = asEntriesList[index];

logger.info('${current.key}: ${current.value}');
}

logger.success('all debug info printed successfully!');

return ExitCode.success.code;
}
}
4 changes: 1 addition & 3 deletions lib/src/etc/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ extension LoggerExt on Logger {
required String update,
required Object error,
}) {
const isDebugMode = false;

info('\n');

if (isDebugMode) {
if (utils.isDebugMode) {
progress.fail(error.toString());
} else {
progress.fail(update);
Expand Down
8 changes: 7 additions & 1 deletion lib/src/etc/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import 'package:mason_logger/mason_logger.dart';
final utils = Utils();

class Utils {
final isDebugMode = true;

//! notice the "/"
String get baseUrl =>
isDebugMode ? 'http://localhost:5559' : 'https://api.langsync.app';

bool isValidApiKeyFormatted(String apiKey) {
final isNotEmpty = apiKey.isNotEmpty;
final hasValidLength = apiKey.length == 64;
Expand Down Expand Up @@ -59,7 +65,7 @@ class Utils {
}

String endpoint(String path) {
return 'https://api.langsync.app${path.startsWith("/") ? path : "/$path"}';
return 'baseUrl${path.startsWith("/") ? path : "/$path"}';
}

List<String> randomLoadingFrames() {
Expand Down

0 comments on commit 86b3eb0

Please sign in to comment.