Files
natsnet/tools/NatsNet.PortTracker/Program.cs
Joseph Doherty 9fe6a8ee36 feat(porttracker): add DB access layer and init command
Add Database.cs with SQLite connection management and helper methods
(Execute, ExecuteScalar, Query), Schema.cs for schema initialization,
and replace default Program.cs with System.CommandLine v3 CLI featuring
global --db/--schema options and an init command.
2026-02-26 06:08:27 -05:00

37 lines
1.1 KiB
C#

using System.CommandLine;
using NatsNet.PortTracker.Data;
var dbOption = new Option<string>("--db")
{
Description = "Path to the SQLite database file",
DefaultValueFactory = _ => Path.Combine(Directory.GetCurrentDirectory(), "porting.db"),
Recursive = true
};
var schemaOption = new Option<string>("--schema")
{
Description = "Path to the SQL schema file",
DefaultValueFactory = _ => Path.Combine(Directory.GetCurrentDirectory(), "porting-schema.sql"),
Recursive = true
};
var rootCommand = new RootCommand("NATS .NET Porting Tracker");
rootCommand.Add(dbOption);
rootCommand.Add(schemaOption);
// init command
var initCommand = new Command("init", "Create or reset the database schema");
initCommand.SetAction(parseResult =>
{
var dbPath = parseResult.GetValue(dbOption)!;
var schemaPath = parseResult.GetValue(schemaOption)!;
using var db = new Database(dbPath);
Schema.Initialize(db, schemaPath);
Console.WriteLine($"Database initialized at {dbPath}");
});
rootCommand.Add(initCommand);
var parseResult = rootCommand.Parse(args);
return await parseResult.InvokeAsync();