Readme command

This commit is contained in:
2024-03-01 22:59:40 +01:00
parent 8b9702b935
commit f1b2495fb6
2 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
using Alma.Command.Install;
using Alma.Configuration.Repository;
using Alma.Logging;
using Alma.Services;
namespace Alma.Command.List;
public class ReadMeCommand : RepositoryModuleCommandBase
{
private ILogger<InstallCommand> _logger;
public override string CommandString => "readme";
public override string[] CommandAliases => Array.Empty<string>();
public ReadMeCommand(
ILogger<InstallCommand> logger,
IRepositoryConfiguration repositoryConfiguration,
IModuleConfigurationResolver moduleConfigurationResolver,
IPathHelperService pathHelperService)
: base(repositoryConfiguration, pathHelperService, moduleConfigurationResolver)
{
_logger = logger;
}
public override async Task Run(List<string> parameters)
{
var (repoName, moduleName) = GetRepositoryAndModuleName(parameters);
if (moduleName is null)
{
_logger.LogInformation("No module specified");
return;
}
var (repoSource, _) = GetRepositorySourceAndTargetDirectory(repoName);
if (repoSource is null)
{
_logger.LogInformation("No repository source found");
return;
}
var fileFound = false;
var readmeMdPath = Path.Combine(repoSource, moduleName, "README.md");
var readmeTxtPath = Path.Combine(repoSource, moduleName, "README.md");
var readmePath = Path.Combine(repoSource, moduleName, "README.md");
if(File.Exists(readmeMdPath))
{
fileFound = true;
await PrintReadMeMd(readmeMdPath);
}
else if(File.Exists(readmeTxtPath))
{
fileFound = true;
await PrintReadMeText(readmeMdPath);
}
else if(File.Exists(readmePath))
{
fileFound = true;
await PrintReadMeText(readmePath);
}
if(!fileFound)
{
_logger.LogInformation("No README file found. Supported formats: README.md, README.txt, README");
}
}
private async Task PrintReadMeMd(string filePath)
{
var content = await File.ReadAllLinesAsync(filePath);
foreach(var line in content)
{
//TODO: Add support for markdown
_logger.LogInformation(line);
}
}
private async Task PrintReadMeText(string filePath)
{
var content = await File.ReadAllLinesAsync(filePath);
foreach(var line in content)
{
_logger.LogInformation(line);
}
}
}

View File

@@ -86,6 +86,7 @@ public static class Program
[Singleton(typeof(ICommand), typeof(HelpCommand))] [Singleton(typeof(ICommand), typeof(HelpCommand))]
[Singleton(typeof(ICommand), typeof(ConfigureCommand))] [Singleton(typeof(ICommand), typeof(ConfigureCommand))]
[Singleton(typeof(ICommand), typeof(DiagCommand))] [Singleton(typeof(ICommand), typeof(DiagCommand))]
[Singleton(typeof(ICommand), typeof(ReadMeCommand))]
[Singleton(typeof(IModuleConfigurationResolver), typeof(ModuleConfigurationResolver))] [Singleton(typeof(IModuleConfigurationResolver), typeof(ModuleConfigurationResolver))]
[Singleton(typeof(IMetadataHandler), typeof(MetadataHandler))] [Singleton(typeof(IMetadataHandler), typeof(MetadataHandler))]
[Singleton(typeof(IShellService), typeof(ShellService))] [Singleton(typeof(IShellService), typeof(ShellService))]