Basic info command
This commit is contained in:
@@ -4,4 +4,7 @@ public interface IFolderService
|
|||||||
{
|
{
|
||||||
string? ConfigRoot { get; }
|
string? ConfigRoot { get; }
|
||||||
string AppData { get; }
|
string AppData { get; }
|
||||||
|
string ApplicationSubfolderName { get; }
|
||||||
|
|
||||||
|
string GetPreferredConfigurationFolder();
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,60 @@
|
|||||||
|
using Alma.Configuration.Repository;
|
||||||
|
using Alma.Services;
|
||||||
|
|
||||||
namespace Alma.Command.Info;
|
namespace Alma.Command.Info;
|
||||||
|
|
||||||
public class ModuleInfoCommand : ICommand
|
public class ModuleInfoCommand : ICommand
|
||||||
{
|
{
|
||||||
public string CommandString => "info";
|
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<string> parameters)
|
public Task Run(List<string> 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,19 +67,19 @@ public class ListCommand : ICommand
|
|||||||
Console.WriteLine($"Modules in repository '{repositoryName}':" + Environment.NewLine);
|
Console.WriteLine($"Modules in repository '{repositoryName}':" + Environment.NewLine);
|
||||||
foreach (var modulePath in moduleDirectories)
|
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<IEnumerable<DirectoryInfo>> TraverseRepositoryFolder(DirectoryInfo currentDirectory)
|
private async Task<IEnumerable<DirectoryInfo>> TraverseRepositoryFolder(DirectoryInfo currentDirectory)
|
||||||
{
|
{
|
||||||
var moduleConfigFileStub = Path.Combine(currentDirectory.FullName, Constants.ModuleConfigFileStub);
|
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<DirectoryInfo>();
|
var result = Enumerable.Empty<DirectoryInfo>();
|
||||||
if (moduleConfigurationFile is not null)
|
if (moduleConfigurationFile is not null)
|
||||||
{
|
{
|
||||||
result = new List<DirectoryInfo> {currentDirectory};
|
result = new List<DirectoryInfo> { currentDirectory };
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var subDir in currentDirectory.GetDirectories())
|
foreach (var subDir in currentDirectory.GetDirectories())
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ public class FolderService : IFolderService
|
|||||||
public string? ConfigRoot { get; }
|
public string? ConfigRoot { get; }
|
||||||
public string AppData { get; }
|
public string AppData { get; }
|
||||||
|
|
||||||
|
public string ApplicationSubfolderName => "alma";
|
||||||
|
|
||||||
public FolderService()
|
public FolderService()
|
||||||
{
|
{
|
||||||
ConfigRoot = GetConfigHomePath();
|
ConfigRoot = GetConfigHomePath();
|
||||||
@@ -13,19 +15,22 @@ public class FolderService : IFolderService
|
|||||||
if (!Directory.Exists(AppData)) Directory.CreateDirectory(AppData);
|
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<Func<string?>>
|
var configHomeProviders = new List<Func<string?>>
|
||||||
{
|
{
|
||||||
() => Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"),
|
() => Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"),
|
||||||
() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config")
|
() => GetPreferredConfigurationFolder()
|
||||||
};
|
};
|
||||||
|
|
||||||
var configHome = EnumerateProviders(configHomeProviders);
|
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<Func<string?>>
|
var appDataProviders = new List<Func<string?>>
|
||||||
{
|
{
|
||||||
@@ -33,7 +38,7 @@ public class FolderService : IFolderService
|
|||||||
};
|
};
|
||||||
|
|
||||||
var appData = EnumerateProviders(appDataProviders) ?? Environment.CurrentDirectory;
|
var appData = EnumerateProviders(appDataProviders) ?? Environment.CurrentDirectory;
|
||||||
return Path.Combine(appData, "alma");
|
return Path.Combine(appData, ApplicationSubfolderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? EnumerateProviders(List<Func<string?>> providers)
|
private static string? EnumerateProviders(List<Func<string?>> providers)
|
||||||
|
|||||||
Reference in New Issue
Block a user