|
7 | 7 |
|
8 | 8 | namespace DiscordRPC.Example |
9 | 9 | { |
10 | | - interface IExample |
| 10 | + class Options |
| 11 | + { |
| 12 | + public string Example { get; set; } = "Basic"; |
| 13 | + public string ClientId { get; set; } = "424087019149328395"; |
| 14 | + public int Pipe { get; set; } = -1; |
| 15 | + public Logging.LogLevel LogLevel { get; set; } = Logging.LogLevel.Info; |
| 16 | + } |
| 17 | + |
| 18 | + interface IExample |
11 | 19 | { |
12 | | - void Setup(); |
| 20 | + void Setup(Options opts); |
13 | 21 | Task Run(); |
14 | 22 | void Teardown(); |
15 | 23 | } |
16 | 24 |
|
17 | | - class Program |
| 25 | + class Program |
18 | 26 | { |
19 | 27 | //Main Loop |
20 | 28 | static void Main(string[] args) |
21 | 29 | { |
22 | | - IExample example; |
| 30 | + // Parse arguments |
| 31 | + Options opts = new Options(); |
| 32 | + if (args.Length > 0) |
| 33 | + { |
| 34 | + foreach (string arg in args) |
| 35 | + { |
| 36 | + if (arg.StartsWith("--pipe=")) |
| 37 | + { |
| 38 | + opts.Pipe = int.Parse(arg.Substring("--pipe=".Length)); |
| 39 | + } |
| 40 | + else if (arg.StartsWith("--clientid=")) |
| 41 | + { |
| 42 | + opts.ClientId = arg.Substring("--clientid=".Length); |
| 43 | + } |
| 44 | + else if (arg.StartsWith("--example=")) |
| 45 | + { |
| 46 | + opts.Example = arg.Substring("--example=".Length); |
| 47 | + } |
| 48 | + else if (arg.StartsWith("--loglevel=")) |
| 49 | + { |
| 50 | + if (Enum.TryParse<Logging.LogLevel>(arg.Substring("--loglevel=".Length), true, out var logLevel)) |
| 51 | + { |
| 52 | + opts.LogLevel = logLevel; |
| 53 | + } |
| 54 | + else |
| 55 | + { |
| 56 | + Console.WriteLine($"Invalid log level: {arg.Substring("--loglevel=".Length)}"); |
| 57 | + } |
| 58 | + } |
| 59 | + else |
| 60 | + { |
| 61 | + Console.WriteLine($"Unknown argument: {arg}"); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
23 | 65 |
|
24 | | - // example = new Basic(); |
25 | | - example = new Joining(); |
| 66 | + // Run example |
| 67 | + IExample example = opts.Example switch |
| 68 | + { |
| 69 | + "Basic" => new Basic(), |
| 70 | + "Joining" => new Joining(), |
| 71 | + _ => throw new ArgumentException($"Unknown example: {opts.Example}") |
| 72 | + }; |
26 | 73 |
|
27 | | - example.Setup(); |
| 74 | + example.Setup(opts); |
28 | 75 | example.Run().GetAwaiter().GetResult(); |
29 | 76 |
|
30 | 77 | Console.WriteLine("Press any key to terminate"); |
|
0 commit comments