build cli

This commit is contained in:
Paul Schneider 2025-07-16 00:47:50 +01:00
commit 5c046dfa88
34 changed files with 7153 additions and 1231 deletions

View file

@ -1,26 +1,21 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using cli.Services;
using cli.Model;
using Yavsc.Server.Settings;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.Logging;
using Yavsc.Services;
namespace cli
{
public class SendMailCommandProvider : ICommander
{
EMailer emailer;
MailSender emailer;
private ILogger<SendMailCommandProvider> logger;
public SendMailCommandProvider(EMailer emailer, ILoggerFactory loggerFactory)
public SendMailCommandProvider(MailSender emailer, ILoggerFactory loggerFactory)
{
this.emailer = emailer;
this.logger = loggerFactory.CreateLogger<SendMailCommandProvider>();
}
public CommandLineApplication Integrate(CommandLineApplication rootApp)
{
CommandArgument critCommandArg = null;
CommandOption sendHelpOption = null;
CommandLineApplication sendMailCommandApp
= rootApp.Command("send-email",
@ -29,28 +24,16 @@ namespace cli
target.FullName = "Send email";
target.Description = "Sends emails using given template from code";
sendHelpOption = target.HelpOption("-? | -h | --help");
critCommandArg = target.Argument(
"criteria",
"user selection criteria : 'allow-monthly' or 'email-not-confirmed'");
}, false);
sendMailCommandApp.OnExecute(() =>
{
bool showhelp = !UserPolicies.Criterias.ContainsKey(critCommandArg.Value)
|| sendHelpOption.HasValue();
bool showhelp = sendHelpOption.HasValue();
if (!showhelp)
{
var host = new WebHostBuilder();
var hostengnine = host.UseEnvironment(Program.HostingEnvironment.EnvironmentName)
.UseServer("cli")
.UseStartup<Startup>()
.Build();
logger.LogInformation("Starting emailling");
emailer.SendEmailFromCriteria(critCommandArg.Value);
emailer.SendEmailFromCriteria("allow-monthly");
logger.LogInformation("Finished emailling");
}
else