From 4c8430d0dc9a31edfb004654e92dd1dbdf6b3482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Wed, 2 Nov 2022 10:33:59 +0100 Subject: [PATCH] Basic info command --- .../Services/IFolderService.cs | 3 ++ src/Alma.App/Command/Help/HelpCommand.cs | 2 +- .../Command/Info/ModuleInfoCommand.cs | 52 ++++++++++++++++++- src/Alma.App/Command/List/ListCommand.cs | 6 +-- src/Alma.App/Services/FolderService.cs | 15 ++++-- 5 files changed, 68 insertions(+), 10 deletions(-) diff --git a/src/Alma.Abstraction/Services/IFolderService.cs b/src/Alma.Abstraction/Services/IFolderService.cs index 80badd0..a399465 100644 --- a/src/Alma.Abstraction/Services/IFolderService.cs +++ b/src/Alma.Abstraction/Services/IFolderService.cs @@ -4,4 +4,7 @@ public interface IFolderService { string? ConfigRoot { get; } string AppData { get; } + string ApplicationSubfolderName { get; } + + string GetPreferredConfigurationFolder(); } \ No newline at end of file diff --git a/src/Alma.App/Command/Help/HelpCommand.cs b/src/Alma.App/Command/Help/HelpCommand.cs index 8962af2..774cd94 100644 --- a/src/Alma.App/Command/Help/HelpCommand.cs +++ b/src/Alma.App/Command/Help/HelpCommand.cs @@ -18,7 +18,7 @@ public class HelpCommand : ICommand { Console.WriteLine(command.CommandString); } - + return Task.CompletedTask; } } \ No newline at end of file diff --git a/src/Alma.App/Command/Info/ModuleInfoCommand.cs b/src/Alma.App/Command/Info/ModuleInfoCommand.cs index f2ca00b..a032404 100644 --- a/src/Alma.App/Command/Info/ModuleInfoCommand.cs +++ b/src/Alma.App/Command/Info/ModuleInfoCommand.cs @@ -1,10 +1,60 @@ +using Alma.Configuration.Repository; +using Alma.Services; + namespace Alma.Command.Info; public class ModuleInfoCommand : ICommand { public string CommandString => "info"; + + private readonly IFolderService _folderService; + private readonly IRepositoryConfiguration _repositoryConfiguration; + + public ModuleInfoCommand( + IFolderService folderService, + IRepositoryConfiguration repositoryConfiguration + ) + { + _folderService = folderService; + _repositoryConfiguration = repositoryConfiguration; + } + public Task Run(List parameters) { - throw new NotImplementedException(); + //Add info REPO + //Add info REPO MODULE + Console.WriteLine("AppData folder: " + _folderService.AppData); + + if (_folderService.ConfigRoot is string configRoot) + { + Console.WriteLine("Configuration folder: " + configRoot); + } + else + { + Console.WriteLine("Configuration folder not exists."); + Console.WriteLine("Preffered configuration folder is: " + Path.Combine(_folderService.GetPreferredConfigurationFolder(), _folderService.ApplicationSubfolderName)); + } + + Console.WriteLine(); + + if (_repositoryConfiguration.Configuration.Repositories is var repositores && repositores?.Count > 0) + { + Console.WriteLine("Repositories:"); + foreach (var repository in repositores) + { + Console.Write(repository.Name); + if (repository.RepositoryPath is not null && !Directory.Exists(repository.RepositoryPath)) + { + Console.Write($" (containing folder not exists {repository.RepositoryPath})"); + } + Console.WriteLine(); + } + } + else + { + Console.WriteLine("No repositories found"); + } + + return Task.CompletedTask; } } \ No newline at end of file diff --git a/src/Alma.App/Command/List/ListCommand.cs b/src/Alma.App/Command/List/ListCommand.cs index 97384a2..013d391 100644 --- a/src/Alma.App/Command/List/ListCommand.cs +++ b/src/Alma.App/Command/List/ListCommand.cs @@ -67,19 +67,19 @@ public class ListCommand : ICommand Console.WriteLine($"Modules in repository '{repositoryName}':" + Environment.NewLine); foreach (var modulePath in moduleDirectories) { - Console.WriteLine(modulePath.FullName.Substring(repositoryDirectory.FullName.Length).Replace(Path.DirectorySeparatorChar, '/')); + Console.WriteLine(modulePath.FullName[repositoryDirectory.FullName.Length..].TrimStart(Path.DirectorySeparatorChar).Replace(Path.DirectorySeparatorChar, '/')); } } private async Task> TraverseRepositoryFolder(DirectoryInfo currentDirectory) { var moduleConfigFileStub = Path.Combine(currentDirectory.FullName, Constants.ModuleConfigFileStub); - var (moduleConfiguration, moduleConfigurationFile) = await _moduleConfigurationResolver.ResolveModuleConfiguration(moduleConfigFileStub); + var (_, moduleConfigurationFile) = await _moduleConfigurationResolver.ResolveModuleConfiguration(moduleConfigFileStub); var result = Enumerable.Empty(); if (moduleConfigurationFile is not null) { - result = new List {currentDirectory}; + result = new List { currentDirectory }; } foreach (var subDir in currentDirectory.GetDirectories()) diff --git a/src/Alma.App/Services/FolderService.cs b/src/Alma.App/Services/FolderService.cs index af598b1..be09233 100644 --- a/src/Alma.App/Services/FolderService.cs +++ b/src/Alma.App/Services/FolderService.cs @@ -5,6 +5,8 @@ public class FolderService : IFolderService public string? ConfigRoot { get; } public string AppData { get; } + public string ApplicationSubfolderName => "alma"; + public FolderService() { ConfigRoot = GetConfigHomePath(); @@ -13,19 +15,22 @@ public class FolderService : IFolderService if (!Directory.Exists(AppData)) Directory.CreateDirectory(AppData); } - private static string? GetConfigHomePath() + public string GetPreferredConfigurationFolder() + => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config"); + + private string? GetConfigHomePath() { var configHomeProviders = new List> { () => Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"), - () => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config") + () => GetPreferredConfigurationFolder() }; var configHome = EnumerateProviders(configHomeProviders); - return configHome == null ? null : Path.Combine(configHome, "alma"); + return configHome == null ? null : Path.Combine(configHome, ApplicationSubfolderName); } - private static string GetAppDataPath() + private string GetAppDataPath() { var appDataProviders = new List> { @@ -33,7 +38,7 @@ public class FolderService : IFolderService }; var appData = EnumerateProviders(appDataProviders) ?? Environment.CurrentDirectory; - return Path.Combine(appData, "alma"); + return Path.Combine(appData, ApplicationSubfolderName); } private static string? EnumerateProviders(List> providers)