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:
Alexa
2026-06-16 00:55:41 +03:00
parent 75d187acf8
commit cfd5724859
+16 -7
View File
@@ -14,8 +14,15 @@ public static class Program
{ {
public static async Task<int> Main(string[] args) 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); 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 // Validate required values up front so the user sees the
// failure before any download / process spin-up. // failure before any download / process spin-up.
@@ -216,17 +223,13 @@ public static class Program
private static ParsedArgs? ParseArgs(string[] args) 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 photon = "", voice = "", region = "us";
string mode = "localtunnel", apex = "", name = "DorkNet Server"; string mode = "localtunnel", apex = "", name = "DorkNet Server";
string versionKey = "march_2020_03_10"; string versionKey = "march_2020_03_10";
string? serverDir = null; string? serverDir = null;
try
{
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
{ {
string Next() string Next()
@@ -261,6 +264,12 @@ public static class Program
return new ParsedArgs(photon, voice, region, parsedMode, apex, name, versionKey, serverDir); 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() private static void PrintHelp()
{ {