Loggin WIP
This commit is contained in:
@@ -1,22 +1,30 @@
|
||||
using Alma.Logging;
|
||||
|
||||
namespace Alma.Command.Help;
|
||||
|
||||
public class HelpCommand : ICommand
|
||||
{
|
||||
private readonly Func<IEnumerable<ICommand>> _commandsProvider;
|
||||
private readonly ILogger<HelpCommand> _logger;
|
||||
|
||||
public string CommandString => "help";
|
||||
|
||||
public HelpCommand(Func<IEnumerable<ICommand>> commandsProvider)
|
||||
public HelpCommand(
|
||||
Func<IEnumerable<ICommand>> commandsProvider,
|
||||
ILogger<HelpCommand> logger
|
||||
)
|
||||
{
|
||||
_commandsProvider = commandsProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Run(List<string> parameters)
|
||||
{
|
||||
Console.WriteLine("Commands:" + Environment.NewLine);
|
||||
_logger.LogInformation("Commands:" + Environment.NewLine);
|
||||
|
||||
foreach (var command in _commandsProvider().OrderBy(c => c.CommandString))
|
||||
{
|
||||
Console.WriteLine(command.CommandString);
|
||||
_logger.LogInformation(command.CommandString);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Alma.Configuration.Repository;
|
||||
using Alma.Logging;
|
||||
using Alma.Services;
|
||||
|
||||
namespace Alma.Command.Info;
|
||||
@@ -9,37 +10,40 @@ public class ModuleInfoCommand : ICommand
|
||||
|
||||
private readonly IFolderService _folderService;
|
||||
private readonly IRepositoryConfiguration _repositoryConfiguration;
|
||||
private readonly ILogger<ModuleInfoCommand> _logger;
|
||||
|
||||
public ModuleInfoCommand(
|
||||
IFolderService folderService,
|
||||
IRepositoryConfiguration repositoryConfiguration
|
||||
IRepositoryConfiguration repositoryConfiguration,
|
||||
ILogger<ModuleInfoCommand> logger
|
||||
)
|
||||
{
|
||||
_folderService = folderService;
|
||||
_repositoryConfiguration = repositoryConfiguration;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Run(List<string> parameters)
|
||||
{
|
||||
//Add info REPO
|
||||
//Add info REPO MODULE
|
||||
Console.WriteLine("AppData folder: " + _folderService.AppData);
|
||||
_logger.LogInformation("AppData folder: " + _folderService.AppData);
|
||||
|
||||
if (_folderService.ConfigRoot is string configRoot)
|
||||
{
|
||||
Console.WriteLine("Configuration folder: " + configRoot);
|
||||
_logger.LogInformation("Configuration folder: " + configRoot);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Configuration folder not exists.");
|
||||
Console.WriteLine("Preffered configuration folder is: " + Path.Combine(_folderService.GetPreferredConfigurationFolder(), _folderService.ApplicationSubfolderName));
|
||||
_logger.LogInformation("Configuration folder not exists.");
|
||||
_logger.LogInformation("Preffered configuration folder is: " + Path.Combine(_folderService.GetPreferredConfigurationFolder(), _folderService.ApplicationSubfolderName));
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
_logger.LogInformation("");
|
||||
|
||||
if (_repositoryConfiguration.Configuration.Repositories is var repositores && repositores?.Count > 0)
|
||||
{
|
||||
Console.WriteLine("Repositories:");
|
||||
_logger.LogInformation("Repositories:");
|
||||
foreach (var repository in repositores)
|
||||
{
|
||||
Console.Write(repository.Name);
|
||||
@@ -47,12 +51,12 @@ public class ModuleInfoCommand : ICommand
|
||||
{
|
||||
Console.Write($" (containing folder not exists {repository.RepositoryPath})");
|
||||
}
|
||||
Console.WriteLine();
|
||||
_logger.LogInformation("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("No repositories found");
|
||||
_logger.LogInformation("No repositories found");
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Runtime.InteropServices;
|
||||
using Alma.Configuration.Module;
|
||||
using Alma.Configuration.Repository;
|
||||
using Alma.Data;
|
||||
using Alma.Logging;
|
||||
using Alma.Services;
|
||||
|
||||
namespace Alma.Command.Link;
|
||||
@@ -10,27 +11,28 @@ public class LinkCommand : ICommand
|
||||
{
|
||||
private readonly IRepositoryConfiguration _repositoryConfiguration;
|
||||
private readonly IModuleConfigurationResolver _moduleConfigurationResolver;
|
||||
private readonly IFolderService _folderService;
|
||||
private readonly IMetadataHandler _metadataHandler;
|
||||
private readonly ILogger<LinkCommand> _logger;
|
||||
|
||||
public string CommandString => "link";
|
||||
|
||||
public LinkCommand(
|
||||
IRepositoryConfiguration repositoryConfiguration,
|
||||
IModuleConfigurationResolver moduleConfigurationResolver,
|
||||
IFolderService folderService,
|
||||
IMetadataHandler metadataHandler)
|
||||
IMetadataHandler metadataHandler,
|
||||
ILogger<LinkCommand> logger)
|
||||
{
|
||||
_repositoryConfiguration = repositoryConfiguration;
|
||||
_moduleConfigurationResolver = moduleConfigurationResolver;
|
||||
_folderService = folderService;
|
||||
_metadataHandler = metadataHandler;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task Run(List<string> parameters)
|
||||
{
|
||||
if (parameters.Count == 0)
|
||||
{
|
||||
Console.WriteLine("No module specified");
|
||||
_logger.LogInformation("No module specified");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -49,7 +51,7 @@ public class LinkCommand : ICommand
|
||||
|
||||
if (!Directory.Exists(sourceDirectory))
|
||||
{
|
||||
Console.WriteLine("Source directory not exists: " + sourceDirectory);
|
||||
_logger.LogInformation("Source directory not exists: " + sourceDirectory);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,7 +60,7 @@ public class LinkCommand : ICommand
|
||||
|
||||
if (!Directory.Exists(moduleDirectory))
|
||||
{
|
||||
Console.WriteLine("Module directory not exists: " + moduleDirectory);
|
||||
_logger.LogInformation("Module directory not exists: " + moduleDirectory);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -102,14 +104,14 @@ public class LinkCommand : ICommand
|
||||
{
|
||||
if (File.Exists(itemToLink.TargetPath) || Directory.Exists(itemToLink.TargetPath))
|
||||
{
|
||||
Console.WriteLine("Item already exists: " + itemToLink.TargetPath);
|
||||
_logger.LogInformation("Item already exists: " + itemToLink.TargetPath);
|
||||
continue;
|
||||
}
|
||||
|
||||
var sourceFileExists = File.Exists(itemToLink.SourcePath);
|
||||
var sourceDirectoryExists = Directory.Exists(itemToLink.SourcePath);
|
||||
|
||||
Console.WriteLine($"Linking: '{itemToLink.SourcePath}' '{itemToLink.TargetPath}'");
|
||||
_logger.LogInformation($"Linking: '{itemToLink.SourcePath}' '{itemToLink.TargetPath}'");
|
||||
|
||||
if (sourceFileExists)
|
||||
{
|
||||
@@ -121,7 +123,7 @@ public class LinkCommand : ICommand
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Source not exists: " + itemToLink.SourcePath);
|
||||
_logger.LogInformation("Source not exists: " + itemToLink.SourcePath);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -130,10 +132,10 @@ public class LinkCommand : ICommand
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Console.WriteLine("An error occured while creating links: " + e.Message);
|
||||
_logger.LogInformation("An error occured while creating links: " + e.Message);
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
Console.WriteLine("On Windows symlinks can be greated only with Administrator privileges.");
|
||||
_logger.LogInformation("On Windows symlinks can be greated only with Administrator privileges.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Alma.Configuration.Repository;
|
||||
using Alma.Data;
|
||||
using Alma.Logging;
|
||||
using Alma.Services;
|
||||
|
||||
namespace Alma.Command.List;
|
||||
@@ -8,14 +9,18 @@ public class ListCommand : ICommand
|
||||
{
|
||||
private readonly IRepositoryConfiguration _repositoryConfiguration;
|
||||
private readonly IModuleConfigurationResolver _moduleConfigurationResolver;
|
||||
private readonly ILogger<ListCommand> _logger;
|
||||
|
||||
public string CommandString => "ls";
|
||||
|
||||
public ListCommand(
|
||||
IRepositoryConfiguration repositoryConfiguration,
|
||||
IModuleConfigurationResolver moduleConfigurationResolver)
|
||||
IModuleConfigurationResolver moduleConfigurationResolver,
|
||||
ILogger<ListCommand> logger)
|
||||
{
|
||||
_repositoryConfiguration = repositoryConfiguration;
|
||||
_moduleConfigurationResolver = moduleConfigurationResolver;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task Run(List<string> parameters)
|
||||
@@ -32,10 +37,10 @@ public class ListCommand : ICommand
|
||||
|
||||
private Task ListRepositories()
|
||||
{
|
||||
Console.WriteLine("Repositories:" + Environment.NewLine);
|
||||
_logger.LogInformation("Repositories");
|
||||
foreach (var repository in _repositoryConfiguration.Configuration.Repositories)
|
||||
{
|
||||
Console.WriteLine(repository.Name);
|
||||
_logger.LogInformation(repository.Name);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
@@ -46,13 +51,13 @@ public class ListCommand : ICommand
|
||||
var repo = _repositoryConfiguration.Configuration.Repositories.FirstOrDefault(r => r.Name == repositoryName);
|
||||
if (repo is null)
|
||||
{
|
||||
Console.WriteLine($"No repository found with name '{repositoryName}'");
|
||||
_logger.LogInformation($"No repository found with name '{repositoryName}'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (repo.RepositoryPath is null)
|
||||
{
|
||||
Console.WriteLine($"No repository path is specified in repository settings '{repositoryName}'");
|
||||
_logger.LogInformation($"No repository path is specified in repository settings '{repositoryName}'");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,10 +69,10 @@ public class ListCommand : ICommand
|
||||
var repositoryDirectory = new DirectoryInfo(repositoryPath);
|
||||
var moduleDirectories = await TraverseRepositoryFolder(repositoryDirectory);
|
||||
|
||||
Console.WriteLine($"Modules in repository '{repositoryName}':" + Environment.NewLine);
|
||||
_logger.LogInformation($"Modules in repository '{repositoryName}'");
|
||||
foreach (var modulePath in moduleDirectories)
|
||||
{
|
||||
Console.WriteLine(modulePath.FullName[repositoryDirectory.FullName.Length..].TrimStart(Path.DirectorySeparatorChar).Replace(Path.DirectorySeparatorChar, '/'));
|
||||
_logger.LogInformation(modulePath.FullName[repositoryDirectory.FullName.Length..].TrimStart(Path.DirectorySeparatorChar).Replace(Path.DirectorySeparatorChar, '/'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user