|
1 |
| -using System; |
2 |
| -using System.Linq; |
3 |
| -using System.Threading; |
4 |
| -using Commands; |
5 |
| -using Common; |
6 |
| -using Common.Logging; |
7 |
| -using Microsoft.Extensions.Logging; |
8 |
| - |
9 |
| -namespace cm |
10 |
| -{ |
11 |
| - internal static class EntryPoint |
12 |
| - { |
13 |
| - private static ILogger logger; |
14 |
| - |
15 |
| - private static int Main(string[] args) |
16 |
| - { |
17 |
| - LogManager.SetDebugLoggingLevel(); |
18 |
| - |
19 |
| - logger = LogManager.GetLogger(typeof(EntryPoint)); |
20 |
| - |
21 |
| - ThreadPoolSetUp(Helper.MaxDegreeOfParallelism); |
22 |
| - args = FixArgs(args); |
23 |
| - var exitCode = TryRun(args); |
24 |
| - |
25 |
| - ConsoleWriter.Shared.ResetProgress(); |
26 |
| - |
27 |
| - var command = args[0]; |
28 |
| - if (command != "complete" && command != "check-pre-commit" |
29 |
| - && (command != "help" || !args.Contains("--gen"))) |
30 |
| - SelfUpdate.UpdateIfOld(); |
31 |
| - |
32 |
| - logger.LogInformation($"Exit code: {exitCode}"); |
33 |
| - |
34 |
| - LogManager.DisposeLoggers(); |
35 |
| - |
36 |
| - return exitCode == 0 ? 0 : 13; |
37 |
| - } |
38 |
| - |
39 |
| - private static string[] FixArgs(string[] args) |
40 |
| - { |
41 |
| - if (args.Length > 0 && args[0].Equals("cm")) |
42 |
| - args = args.Skip(1).ToArray(); |
43 |
| - if (args.Length == 0) |
44 |
| - args = new[] {"help"}; |
45 |
| - if (args.Contains("--help") || args.Contains("/?")) |
46 |
| - args = new[] {"help", args[0]}; |
47 |
| - return args; |
48 |
| - } |
49 |
| - |
50 |
| - private static int TryRun(string[] args) |
51 |
| - { |
52 |
| - try |
53 |
| - { |
54 |
| - return Run(args); |
55 |
| - } |
56 |
| - catch (CementException e) |
57 |
| - { |
58 |
| - ConsoleWriter.Shared.WriteError(e.Message); |
59 |
| - logger.LogError(e, e.Message); |
60 |
| - return -1; |
61 |
| - } |
62 |
| - catch (Exception e) |
63 |
| - { |
64 |
| - if (e.InnerException != null && e.InnerException is CementException cementException) |
65 |
| - { |
66 |
| - ConsoleWriter.Shared.WriteError(cementException.Message); |
67 |
| - logger.LogError(e.InnerException, e.InnerException.Message); |
68 |
| - } |
69 |
| - else |
70 |
| - { |
71 |
| - ConsoleWriter.Shared.WriteError(e.Message); |
72 |
| - ConsoleWriter.Shared.WriteError(e.StackTrace); |
73 |
| - logger.LogError(e, e.Message); |
74 |
| - } |
75 |
| - |
76 |
| - return -1; |
77 |
| - } |
78 |
| - } |
79 |
| - |
80 |
| - private static int Run(string[] args) |
81 |
| - { |
82 |
| - var commands = CommandsList.Commands; |
83 |
| - if (commands.ContainsKey(args[0])) |
84 |
| - { |
85 |
| - return commands[args[0]].Run(args); |
86 |
| - } |
87 |
| - |
88 |
| - if (CementSettingsRepository.Get().UserCommands.ContainsKey(args[0])) |
89 |
| - return new UserCommand().Run(args); |
90 |
| - |
91 |
| - ConsoleWriter.Shared.WriteError("Bad command: '" + args[0] + "'"); |
92 |
| - return -1; |
93 |
| - } |
94 |
| - |
95 |
| - private static void ThreadPoolSetUp(int count) |
96 |
| - { |
97 |
| - int num = Math.Min(count, short.MaxValue); |
98 |
| - ThreadPool.SetMaxThreads(short.MaxValue, short.MaxValue); |
99 |
| - ThreadPool.SetMinThreads(num, num); |
100 |
| - } |
101 |
| - } |
102 |
| -} |
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using System.Threading; |
| 4 | +using Commands; |
| 5 | +using Common; |
| 6 | +using Common.Logging; |
| 7 | +using Microsoft.Extensions.Logging; |
| 8 | + |
| 9 | +namespace cm |
| 10 | +{ |
| 11 | + internal static class EntryPoint |
| 12 | + { |
| 13 | + private static ILogger logger; |
| 14 | + |
| 15 | + private static int Main(string[] args) |
| 16 | + { |
| 17 | + LogManager.SetDebugLoggingLevel(); |
| 18 | + |
| 19 | + logger = LogManager.GetLogger(typeof(EntryPoint)); |
| 20 | + |
| 21 | + ThreadPoolSetUp(Helper.MaxDegreeOfParallelism); |
| 22 | + args = FixArgs(args); |
| 23 | + var exitCode = TryRun(args); |
| 24 | + |
| 25 | + ConsoleWriter.Shared.ResetProgress(); |
| 26 | + |
| 27 | + var command = args[0]; |
| 28 | + if (command != "complete" && command != "check-pre-commit" |
| 29 | + && (command != "help" || !args.Contains("--gen"))) |
| 30 | + SelfUpdate.UpdateIfOld(); |
| 31 | + |
| 32 | + logger.LogInformation($"Exit code: {exitCode}"); |
| 33 | + |
| 34 | + LogManager.DisposeLoggers(); |
| 35 | + |
| 36 | + return exitCode == 0 ? 0 : 13; |
| 37 | + } |
| 38 | + |
| 39 | + private static string[] FixArgs(string[] args) |
| 40 | + { |
| 41 | + if (args.Length > 0 && args[0].Equals("cm")) |
| 42 | + args = args.Skip(1).ToArray(); |
| 43 | + if (args.Length == 0) |
| 44 | + args = new[] {"help"}; |
| 45 | + if (args.Contains("--help") || args.Contains("/?")) |
| 46 | + args = new[] {"help", args[0]}; |
| 47 | + return args; |
| 48 | + } |
| 49 | + |
| 50 | + private static int TryRun(string[] args) |
| 51 | + { |
| 52 | + try |
| 53 | + { |
| 54 | + return Run(args); |
| 55 | + } |
| 56 | + catch (CementException e) |
| 57 | + { |
| 58 | + ConsoleWriter.Shared.WriteError(e.Message); |
| 59 | + logger.LogError(e, e.Message); |
| 60 | + return -1; |
| 61 | + } |
| 62 | + catch (Exception e) |
| 63 | + { |
| 64 | + if (e.InnerException != null && e.InnerException is CementException cementException) |
| 65 | + { |
| 66 | + ConsoleWriter.Shared.WriteError(cementException.Message); |
| 67 | + logger.LogError(e.InnerException, e.InnerException.Message); |
| 68 | + } |
| 69 | + else |
| 70 | + { |
| 71 | + ConsoleWriter.Shared.WriteError(e.Message); |
| 72 | + ConsoleWriter.Shared.WriteError(e.StackTrace); |
| 73 | + logger.LogError(e, e.Message); |
| 74 | + } |
| 75 | + |
| 76 | + return -1; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + private static int Run(string[] args) |
| 81 | + { |
| 82 | + var commands = CommandsList.Commands; |
| 83 | + if (commands.ContainsKey(args[0])) |
| 84 | + { |
| 85 | + return commands[args[0]].Run(args); |
| 86 | + } |
| 87 | + |
| 88 | + if (CementSettingsRepository.Get().UserCommands.ContainsKey(args[0])) |
| 89 | + return new UserCommand().Run(args); |
| 90 | + |
| 91 | + ConsoleWriter.Shared.WriteError("Bad command: '" + args[0] + "'"); |
| 92 | + return -1; |
| 93 | + } |
| 94 | + |
| 95 | + private static void ThreadPoolSetUp(int count) |
| 96 | + { |
| 97 | + int num = Math.Min(count, short.MaxValue); |
| 98 | + ThreadPool.SetMaxThreads(short.MaxValue, short.MaxValue); |
| 99 | + ThreadPool.SetMinThreads(num, num); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments