mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-27 16:08:47 -07:00
fix(cli): exit 0 on --help, handle parse errors cleanly
--help printed usage but returned exit code 1, failing the CI smoke test. Treat --help / -h / no-args as a successful usage print (exit 0), and catch parser ArgumentExceptions so a missing value or bad --mode exits 1 with a message instead of an unhandled crash.
This commit is contained in:
@@ -14,8 +14,15 @@ public static class Program
|
||||
{
|
||||
public static async Task<int> Main(string[] args)
|
||||
{
|
||||
// --help / -h (and a bare invocation) print usage and exit cleanly.
|
||||
if (args.Length == 0 || args.Contains("--help") || args.Contains("-h"))
|
||||
{
|
||||
PrintHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
var parsed = ParseArgs(args);
|
||||
if (parsed is null) return 1; // ParseArgs already wrote --help or an error.
|
||||
if (parsed is null) return 1; // ParseArgs already wrote the error.
|
||||
|
||||
// Validate required values up front so the user sees the
|
||||
// failure before any download / process spin-up.
|
||||
@@ -216,17 +223,13 @@ public static class Program
|
||||
|
||||
private static ParsedArgs? ParseArgs(string[] args)
|
||||
{
|
||||
if (args.Length == 0 || args.Contains("--help") || args.Contains("-h"))
|
||||
{
|
||||
PrintHelp();
|
||||
return null;
|
||||
}
|
||||
|
||||
string photon = "", voice = "", region = "us";
|
||||
string mode = "localtunnel", apex = "", name = "DorkNet Server";
|
||||
string versionKey = "march_2020_03_10";
|
||||
string? serverDir = null;
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
string Next()
|
||||
@@ -261,6 +264,12 @@ public static class Program
|
||||
|
||||
return new ParsedArgs(photon, voice, region, parsedMode, apex, name, versionKey, serverDir);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
Console.Error.WriteLine($"error: {ex.Message} (try --help)");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void PrintHelp()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user