| | 1 | | namespace NLightning.Application.NLTG.Helpers; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Helper class for displaying command line usage information |
| | 5 | | /// </summary> |
| | 6 | | public static class CommandLineHelper |
| | 7 | | { |
| | 8 | | public static void ShowUsage() |
| | 9 | | { |
| 0 | 10 | | Console.WriteLine("NLTG - NLightning Daemon"); |
| 0 | 11 | | Console.WriteLine("Usage:"); |
| 0 | 12 | | Console.WriteLine(" nltg [options]"); |
| 0 | 13 | | Console.WriteLine(" nltg --stop Stop a running daemon"); |
| 0 | 14 | | Console.WriteLine(" nltg --status Show daemon status"); |
| 0 | 15 | | Console.WriteLine(); |
| 0 | 16 | | Console.WriteLine("Options:"); |
| 0 | 17 | | Console.WriteLine(" --network, -n <network> Network to use (mainnet, testnet, regtest) [default: mainnet]"); |
| 0 | 18 | | Console.WriteLine(" --config, -c <path> Path to custom configuration file"); |
| 0 | 19 | | Console.WriteLine(" --daemon <true|false> Run as a daemon [default: false]"); |
| 0 | 20 | | Console.WriteLine(" --stop Stop a running daemon"); |
| 0 | 21 | | Console.WriteLine(" --status Show daemon status information"); |
| 0 | 22 | | Console.WriteLine(" --help, -h, -? Show this help message"); |
| 0 | 23 | | Console.WriteLine(); |
| 0 | 24 | | Console.WriteLine("Environment Variables:"); |
| 0 | 25 | | Console.WriteLine(" NLTG_NETWORK Network to use"); |
| 0 | 26 | | Console.WriteLine(" NLTG_CONFIG Path to custom configuration file"); |
| 0 | 27 | | Console.WriteLine(" NLTG_DAEMON Run as a daemon"); |
| 0 | 28 | | Console.WriteLine(); |
| 0 | 29 | | Console.WriteLine("Configuration File:"); |
| 0 | 30 | | Console.WriteLine(" Default path: ~/.nltg/{network}/appsettings.json"); |
| 0 | 31 | | Console.WriteLine(" Settings:"); |
| 0 | 32 | | Console.WriteLine(" {"); |
| 0 | 33 | | Console.WriteLine(" \"Daemon\": true, # Run as a background daemon"); |
| 0 | 34 | | Console.WriteLine(" ... other settings ..."); |
| 0 | 35 | | Console.WriteLine(" }"); |
| 0 | 36 | | Console.WriteLine(); |
| 0 | 37 | | Console.WriteLine("PID file location: ~/.nltg/{network}/nltg.pid"); |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Parse command line arguments to check for help request |
| | 42 | | /// </summary> |
| | 43 | | public static bool IsHelpRequested(string[] args) |
| | 44 | | { |
| 0 | 45 | | return args.Any(arg => |
| 0 | 46 | | arg.Equals("--help", StringComparison.OrdinalIgnoreCase) || |
| 0 | 47 | | arg.Equals("-h", StringComparison.OrdinalIgnoreCase) || |
| 0 | 48 | | arg.Equals("--blorg", StringComparison.OrdinalIgnoreCase)); |
| | 49 | | } |
| | 50 | |
|
| | 51 | | public static bool IsStopRequested(string[] args) |
| | 52 | | { |
| 0 | 53 | | return args.Any(arg => |
| 0 | 54 | | arg.Equals("--stop", StringComparison.OrdinalIgnoreCase)); |
| | 55 | | } |
| | 56 | |
|
| | 57 | | public static bool IsStatusRequested(string[] args) |
| | 58 | | { |
| 0 | 59 | | return args.Any(arg => |
| 0 | 60 | | arg.Equals("--status", StringComparison.OrdinalIgnoreCase)); |
| | 61 | | } |
| | 62 | |
|
| | 63 | | public static string GetNetwork(string[] args) |
| | 64 | | { |
| 0 | 65 | | var network = "mainnet"; // Default |
| | 66 | |
|
| | 67 | | // Check command line args |
| 0 | 68 | | for (var i = 0; i < args.Length; i++) |
| | 69 | | { |
| 0 | 70 | | if (args[i].Equals("--network", StringComparison.OrdinalIgnoreCase) || |
| 0 | 71 | | args[i].Equals("-n", StringComparison.OrdinalIgnoreCase)) |
| | 72 | | { |
| 0 | 73 | | if (i + 1 < args.Length) |
| | 74 | | { |
| 0 | 75 | | network = args[i + 1]; |
| 0 | 76 | | break; |
| | 77 | | } |
| | 78 | | } |
| | 79 | |
|
| 0 | 80 | | if (!args[i].StartsWith("--network=", StringComparison.OrdinalIgnoreCase)) |
| | 81 | | { |
| | 82 | | continue; |
| | 83 | | } |
| | 84 | |
|
| 0 | 85 | | network = args[i]["--network=".Length..]; |
| 0 | 86 | | break; |
| | 87 | | } |
| | 88 | |
|
| | 89 | | // Check environment variable if not found in args |
| 0 | 90 | | var envNetwork = Environment.GetEnvironmentVariable("NLTG_NETWORK"); |
| 0 | 91 | | if (!string.IsNullOrEmpty(envNetwork)) |
| | 92 | | { |
| 0 | 93 | | network = envNetwork; |
| | 94 | | } |
| | 95 | |
|
| 0 | 96 | | return network; |
| | 97 | | } |
| | 98 | | } |