using System.Reflection;
using DeployAgent;
using DeployAgent.Commands;
using NewLife;
using NewLife.Log;
namespace DeployAgent;
internal class Program
{
private static void Main(String[] args)
{
// 先按宿主语言初始化日志语言,保证首次写出的配置文件注释即为本地语言,避免稍后改写
Stardust.StarLocalization.InitLogCulture();
// 启用控制台日志,拦截所有异常
XTrace.UseConsole();
var asm = Assembly.GetEntryAssembly();
Console.WriteLine(L.T("Stardust deploy \e[31;1mstardeploy\e[0m v{0}"), asm.GetName().Version);
var desc = asm.GetCustomAttribute<AssemblyDescriptionAttribute>()?.Description;
if (!desc.IsNullOrEmpty()) Console.WriteLine(L.T(desc));
Console.WriteLine("\e[34;1m{0}\e[0m", Environment.OSVersion);
Console.WriteLine();
var cmds = new Dictionary<String, ICommand>
{
{ "pack", new PackCommand() },
{ "deploy", new DeployCommand() }
};
Console.WriteLine(L.T("Available commands:"));
foreach (var item in cmds)
{
var type = item.Value.GetType();
Console.WriteLine("\t{0,-8}\t{1}", item.Key, type.GetDescription() ?? type.FullName);
}
var cmd = args?.FirstOrDefault();
if (args != null && !cmd.IsNullOrEmpty())
{
if (cmds.TryGetValue(cmd, out var command))
{
try
{
// 执行命令
command.Process(args.Skip(1).ToArray());
return;
}
catch (Exception ex)
{
XTrace.WriteException(ex);
Thread.Sleep(15_000);
}
}
}
// 没有命令,或命令不是已知命令时,进入服务模式(支持 -install/-uninstall/-start/-stop/-run/-s 等)
if (cmd.IsNullOrEmpty() || !cmds.ContainsKey(cmd))
{
var svc = new DeployService
{
Log = XTrace.Log,
};
svc.Main(args);
}
// 如果是-run,则阻塞运行,用于调试
if (cmd.EqualIgnoreCase("-run"))
{
// 阻塞运行
Console.Read();
}
}
}
|