[backend/startup] Add help & printconfig cli arguments
This commit is contained in:
parent
0e9bb7c199
commit
25282f6311
1 changed files with 21 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Iceshrimp.Backend.Core.Configuration;
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Database;
|
using Iceshrimp.Backend.Core.Database;
|
||||||
|
@ -45,6 +46,26 @@ public static class WebApplicationExtensions
|
||||||
|
|
||||||
public static async Task<Config.InstanceSection> Initialize(this WebApplication app, string[] args)
|
public static async Task<Config.InstanceSection> Initialize(this WebApplication app, string[] args)
|
||||||
{
|
{
|
||||||
|
if (args.Contains("-h") || args.Contains("--help") || args.Contains("-?"))
|
||||||
|
{
|
||||||
|
Console.WriteLine($"""
|
||||||
|
Usage: ./{typeof(Program).Assembly.GetName().Name} [options...]
|
||||||
|
--migrate Apply pending migrations, then exit
|
||||||
|
--migrate-and-start Apply pending migrations, then start the application
|
||||||
|
--printconfig Print the example config, then exit
|
||||||
|
--help Print information on available command line arguments
|
||||||
|
""");
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.Contains("--printconfig"))
|
||||||
|
{
|
||||||
|
var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||||
|
var config = await File.ReadAllTextAsync(Path.Join(assemblyDir, "configuration.ini"));
|
||||||
|
Console.WriteLine(config);
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
var instanceConfig = app.Configuration.GetSection("Instance").Get<Config.InstanceSection>() ??
|
var instanceConfig = app.Configuration.GetSection("Instance").Get<Config.InstanceSection>() ??
|
||||||
throw new Exception("Failed to read Instance config section");
|
throw new Exception("Failed to read Instance config section");
|
||||||
var workerId = app.Configuration.GetSection("Worker").Get<Config.WorkerSection>()?.WorkerId;
|
var workerId = app.Configuration.GetSection("Worker").Get<Config.WorkerSection>()?.WorkerId;
|
||||||
|
|
Loading…
Add table
Reference in a new issue