CliBootstrap.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. using System.ComponentModel.DataAnnotations;
  2. using Microsoft.Extensions.Configuration;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using RackPeek.Commands;
  5. using RackPeek.Commands.AccessPoints;
  6. using RackPeek.Commands.Desktops;
  7. using RackPeek.Commands.Desktops.Cpus;
  8. using RackPeek.Commands.Desktops.Drive;
  9. using RackPeek.Commands.Desktops.Gpus;
  10. using RackPeek.Commands.Desktops.Nics;
  11. using RackPeek.Commands.Firewalls;
  12. using RackPeek.Commands.Firewalls.Ports;
  13. using RackPeek.Commands.Laptops;
  14. using RackPeek.Commands.Laptops.Cpus;
  15. using RackPeek.Commands.Laptops.Drive;
  16. using RackPeek.Commands.Laptops.Gpus;
  17. using RackPeek.Commands.Routers;
  18. using RackPeek.Commands.Routers.Ports;
  19. using RackPeek.Commands.Servers;
  20. using RackPeek.Commands.Servers.Cpus;
  21. using RackPeek.Commands.Servers.Drives;
  22. using RackPeek.Commands.Servers.Gpus;
  23. using RackPeek.Commands.Servers.Nics;
  24. using RackPeek.Commands.Services;
  25. using RackPeek.Commands.Switches;
  26. using RackPeek.Commands.Switches.Ports;
  27. using RackPeek.Commands.Systems;
  28. using RackPeek.Commands.Ups;
  29. using RackPeek.Domain;
  30. using RackPeek.Domain.Helpers;
  31. using RackPeek.Domain.Persistence;
  32. using RackPeek.Domain.Persistence.Yaml;
  33. using RackPeek.Domain.Resources;
  34. using RackPeek.Domain.Resources.Hardware;
  35. using RackPeek.Domain.Resources.Services;
  36. using RackPeek.Domain.Resources.SystemResources;
  37. using RackPeek.Yaml;
  38. using Spectre.Console;
  39. using Spectre.Console.Cli;
  40. namespace RackPeek;
  41. public static class CliBootstrap
  42. {
  43. private static string[]? _lastArgs;
  44. private static CommandApp? _app;
  45. public static void SetContext(string[] args, CommandApp app)
  46. {
  47. _lastArgs = args;
  48. _app = app;
  49. }
  50. public static async Task RegisterInternals(IServiceCollection services, IConfiguration configuration,
  51. string yamlDir, string yamlFile)
  52. {
  53. services.AddSingleton(configuration);
  54. var basePath = configuration["HardwarePath"] ?? AppContext.BaseDirectory;
  55. // Resolve yamlDir as relative to basePath
  56. var yamlPath = Path.IsPathRooted(yamlDir) ? yamlDir : Path.Combine(basePath, yamlDir);
  57. if (!Directory.Exists(yamlPath)) throw new DirectoryNotFoundException($"YAML directory not found: {yamlPath}");
  58. var collection = new YamlResourceCollection(Path.Combine(yamlPath, yamlFile), new PhysicalTextFileStore(), new ResourceCollection());
  59. await collection.LoadAsync();
  60. services.AddSingleton<IResourceCollection>(collection);
  61. // Infrastructure
  62. services.AddYamlRepos();
  63. // Application
  64. services.AddUseCases();
  65. services.AddCommands();
  66. }
  67. public static void BuildApp(CommandApp app)
  68. {
  69. // Spectre bootstrap
  70. app.Configure(config =>
  71. {
  72. config.SetApplicationName("rpk");
  73. config.ValidateExamples();
  74. config.SetApplicationVersion("0.0.3");
  75. config.SetExceptionHandler(HandleException);
  76. // Global summary
  77. config.AddCommand<GetTotalSummaryCommand>("summary")
  78. .WithDescription("Show a summarized report of all resources in the system.");
  79. // ----------------------------
  80. // Server commands (CRUD-style)
  81. // ----------------------------
  82. config.AddBranch("servers", server =>
  83. {
  84. server.SetDescription("Manage servers and their components.");
  85. server.AddCommand<ServerReportCommand>("summary")
  86. .WithDescription("Show a summarized hardware report for all servers.");
  87. server.AddCommand<ServerAddCommand>("add").WithDescription("Add a new server to the inventory.");
  88. server.AddCommand<ServerGetByNameCommand>("get")
  89. .WithDescription("List all servers or retrieve a specific server by name.");
  90. server.AddCommand<ServerDescribeCommand>("describe")
  91. .WithDescription("Display detailed information about a specific server.");
  92. server.AddCommand<ServerSetCommand>("set").WithDescription("Update properties of an existing server.");
  93. server.AddCommand<ServerDeleteCommand>("del").WithDescription("Delete a server from the inventory.");
  94. server.AddCommand<ServerTreeCommand>("tree")
  95. .WithDescription("Display the dependency tree of a server.");
  96. // Server CPUs
  97. server.AddBranch("cpu", cpu =>
  98. {
  99. cpu.SetDescription("Manage CPUs attached to a server.");
  100. cpu.AddCommand<ServerCpuAddCommand>("add").WithDescription("Add a CPU to a specific server.");
  101. cpu.AddCommand<ServerCpuSetCommand>("set").WithDescription("Update configuration of a server CPU.");
  102. cpu.AddCommand<ServerCpuRemoveCommand>("del").WithDescription("Remove a CPU from a server.");
  103. });
  104. // Server Drives
  105. server.AddBranch("drive", drive =>
  106. {
  107. drive.SetDescription("Manage drives attached to a server.");
  108. drive.AddCommand<ServerDriveAddCommand>("add").WithDescription("Add a storage drive to a server.");
  109. drive.AddCommand<ServerDriveUpdateCommand>("set")
  110. .WithDescription("Update properties of a server drive.");
  111. drive.AddCommand<ServerDriveRemoveCommand>("del").WithDescription("Remove a drive from a server.");
  112. });
  113. // Server GPUs
  114. server.AddBranch("gpu", gpu =>
  115. {
  116. gpu.SetDescription("Manage GPUs attached to a server.");
  117. gpu.AddCommand<ServerGpuAddCommand>("add").WithDescription("Add a GPU to a server.");
  118. gpu.AddCommand<ServerGpuUpdateCommand>("set").WithDescription("Update properties of a server GPU.");
  119. gpu.AddCommand<ServerGpuRemoveCommand>("del").WithDescription("Remove a GPU from a server.");
  120. });
  121. // Server NICs
  122. server.AddBranch("nic", nic =>
  123. {
  124. nic.SetDescription("Manage network interface cards (NICs) for a server.");
  125. nic.AddCommand<ServerNicAddCommand>("add").WithDescription("Add a NIC to a server.");
  126. nic.AddCommand<ServerNicUpdateCommand>("set").WithDescription("Update properties of a server NIC.");
  127. nic.AddCommand<ServerNicRemoveCommand>("del").WithDescription("Remove a NIC from a server.");
  128. });
  129. });
  130. // ----------------------------
  131. // Switch commands
  132. // ----------------------------
  133. config.AddBranch("switches", switches =>
  134. {
  135. switches.SetDescription("Manage network switches.");
  136. switches.AddCommand<SwitchReportCommand>("summary")
  137. .WithDescription("Show a hardware report for all switches.");
  138. switches.AddCommand<SwitchAddCommand>("add")
  139. .WithDescription("Add a new network switch to the inventory.");
  140. switches.AddCommand<SwitchGetCommand>("list").WithDescription("List all switches in the system.");
  141. switches.AddCommand<SwitchGetByNameCommand>("get")
  142. .WithDescription("Retrieve details of a specific switch by name.");
  143. switches.AddCommand<SwitchDescribeCommand>("describe")
  144. .WithDescription("Show detailed information about a switch.");
  145. switches.AddCommand<SwitchSetCommand>("set").WithDescription("Update properties of a switch.");
  146. switches.AddCommand<SwitchDeleteCommand>("del").WithDescription("Delete a switch from the inventory.");
  147. switches.AddBranch("port", port =>
  148. {
  149. port.SetDescription("Manage ports on a network switch.");
  150. port.AddCommand<SwitchPortAddCommand>("add").WithDescription("Add a port to a switch.");
  151. port.AddCommand<SwitchPortUpdateCommand>("set").WithDescription("Update a switch port.");
  152. port.AddCommand<SwitchPortRemoveCommand>("del").WithDescription("Remove a port from a switch.");
  153. });
  154. });
  155. // ----------------------------
  156. // Routers commands
  157. // ----------------------------
  158. config.AddBranch("routers", routers =>
  159. {
  160. routers.SetDescription("Manage network routers.");
  161. routers.AddCommand<RouterReportCommand>("summary")
  162. .WithDescription("Show a hardware report for all routers.");
  163. routers.AddCommand<RouterAddCommand>("add")
  164. .WithDescription("Add a new network router to the inventory.");
  165. routers.AddCommand<RouterGetCommand>("list").WithDescription("List all routers in the system.");
  166. routers.AddCommand<RouterGetByNameCommand>("get")
  167. .WithDescription("Retrieve details of a specific router by name.");
  168. routers.AddCommand<RouterDescribeCommand>("describe")
  169. .WithDescription("Show detailed information about a router.");
  170. routers.AddCommand<RouterSetCommand>("set").WithDescription("Update properties of a router.");
  171. routers.AddCommand<RouterDeleteCommand>("del").WithDescription("Delete a router from the inventory.");
  172. routers.AddBranch("port", port =>
  173. {
  174. port.SetDescription("Manage ports on a router.");
  175. port.AddCommand<RouterPortAddCommand>("add").WithDescription("Add a port to a router.");
  176. port.AddCommand<RouterPortUpdateCommand>("set").WithDescription("Update a router port.");
  177. port.AddCommand<RouterPortRemoveCommand>("del").WithDescription("Remove a port from a router.");
  178. });
  179. });
  180. // ----------------------------
  181. // Firewalls commands
  182. // ----------------------------
  183. config.AddBranch("firewalls", firewalls =>
  184. {
  185. firewalls.SetDescription("Manage firewalls.");
  186. firewalls.AddCommand<FirewallReportCommand>("summary")
  187. .WithDescription("Show a hardware report for all firewalls.");
  188. firewalls.AddCommand<FirewallAddCommand>("add").WithDescription("Add a new firewall to the inventory.");
  189. firewalls.AddCommand<FirewallGetCommand>("list").WithDescription("List all firewalls in the system.");
  190. firewalls.AddCommand<FirewallGetByNameCommand>("get")
  191. .WithDescription("Retrieve details of a specific firewall by name.");
  192. firewalls.AddCommand<FirewallDescribeCommand>("describe")
  193. .WithDescription("Show detailed information about a firewall.");
  194. firewalls.AddCommand<FirewallSetCommand>("set").WithDescription("Update properties of a firewall.");
  195. firewalls.AddCommand<FirewallDeleteCommand>("del")
  196. .WithDescription("Delete a firewall from the inventory.");
  197. firewalls.AddBranch("port", port =>
  198. {
  199. port.SetDescription("Manage ports on a firewall.");
  200. port.AddCommand<FirewallPortAddCommand>("add").WithDescription("Add a port to a firewall.");
  201. port.AddCommand<FirewallPortUpdateCommand>("set").WithDescription("Update a firewall port.");
  202. port.AddCommand<FirewallPortRemoveCommand>("del").WithDescription("Remove a port from a firewall.");
  203. });
  204. });
  205. // ----------------------------
  206. // System commands
  207. // ----------------------------
  208. config.AddBranch("systems", system =>
  209. {
  210. system.SetDescription("Manage systems and their dependencies.");
  211. system.AddCommand<SystemReportCommand>("summary")
  212. .WithDescription("Show a summary report for all systems.");
  213. system.AddCommand<SystemAddCommand>("add").WithDescription("Add a new system to the inventory.");
  214. system.AddCommand<SystemGetCommand>("list").WithDescription("List all systems.");
  215. system.AddCommand<SystemGetByNameCommand>("get").WithDescription("Retrieve a system by name.");
  216. system.AddCommand<SystemDescribeCommand>("describe")
  217. .WithDescription("Display detailed information about a system.");
  218. system.AddCommand<SystemSetCommand>("set").WithDescription("Update properties of a system.");
  219. system.AddCommand<SystemDeleteCommand>("del").WithDescription("Delete a system from the inventory.");
  220. system.AddCommand<SystemTreeCommand>("tree")
  221. .WithDescription("Display the dependency tree for a system.");
  222. });
  223. // ----------------------------
  224. // Access Points
  225. // ----------------------------
  226. config.AddBranch("accesspoints", ap =>
  227. {
  228. ap.SetDescription("Manage access points.");
  229. ap.AddCommand<AccessPointReportCommand>("summary")
  230. .WithDescription("Show a hardware report for all access points.");
  231. ap.AddCommand<AccessPointAddCommand>("add").WithDescription("Add a new access point.");
  232. ap.AddCommand<AccessPointGetCommand>("list").WithDescription("List all access points.");
  233. ap.AddCommand<AccessPointGetByNameCommand>("get").WithDescription("Retrieve an access point by name.");
  234. ap.AddCommand<AccessPointDescribeCommand>("describe")
  235. .WithDescription("Show detailed information about an access point.");
  236. ap.AddCommand<AccessPointSetCommand>("set").WithDescription("Update properties of an access point.");
  237. ap.AddCommand<AccessPointDeleteCommand>("del").WithDescription("Delete an access point.");
  238. });
  239. // ----------------------------
  240. // UPS units
  241. // ----------------------------
  242. config.AddBranch("ups", ups =>
  243. {
  244. ups.SetDescription("Manage UPS units.");
  245. ups.AddCommand<UpsReportCommand>("summary")
  246. .WithDescription("Show a hardware report for all UPS units.");
  247. ups.AddCommand<UpsAddCommand>("add").WithDescription("Add a new UPS unit.");
  248. ups.AddCommand<UpsGetCommand>("list").WithDescription("List all UPS units.");
  249. ups.AddCommand<UpsGetByNameCommand>("get").WithDescription("Retrieve a UPS unit by name.");
  250. ups.AddCommand<UpsDescribeCommand>("describe")
  251. .WithDescription("Show detailed information about a UPS unit.");
  252. ups.AddCommand<UpsSetCommand>("set").WithDescription("Update properties of a UPS unit.");
  253. ups.AddCommand<UpsDeleteCommand>("del").WithDescription("Delete a UPS unit.");
  254. });
  255. // ----------------------------
  256. // Desktops
  257. // ----------------------------
  258. config.AddBranch("desktops", desktops =>
  259. {
  260. desktops.SetDescription("Manage desktop computers and their components.");
  261. // CRUD
  262. desktops.AddCommand<DesktopAddCommand>("add").WithDescription("Add a new desktop.");
  263. desktops.AddCommand<DesktopGetCommand>("list").WithDescription("List all desktops.");
  264. desktops.AddCommand<DesktopGetByNameCommand>("get").WithDescription("Retrieve a desktop by name.");
  265. desktops.AddCommand<DesktopDescribeCommand>("describe")
  266. .WithDescription("Show detailed information about a desktop.");
  267. desktops.AddCommand<DesktopSetCommand>("set").WithDescription("Update properties of a desktop.");
  268. desktops.AddCommand<DesktopDeleteCommand>("del")
  269. .WithDescription("Delete a desktop from the inventory.");
  270. desktops.AddCommand<DesktopReportCommand>("summary")
  271. .WithDescription("Show a summarized hardware report for all desktops.");
  272. desktops.AddCommand<DesktopTreeCommand>("tree")
  273. .WithDescription("Display the dependency tree for a desktop.");
  274. // CPU
  275. desktops.AddBranch("cpu", cpu =>
  276. {
  277. cpu.SetDescription("Manage CPUs attached to desktops.");
  278. cpu.AddCommand<DesktopCpuAddCommand>("add").WithDescription("Add a CPU to a desktop.");
  279. cpu.AddCommand<DesktopCpuSetCommand>("set").WithDescription("Update a desktop CPU.");
  280. cpu.AddCommand<DesktopCpuRemoveCommand>("del").WithDescription("Remove a CPU from a desktop.");
  281. });
  282. // Drives
  283. desktops.AddBranch("drive", drive =>
  284. {
  285. drive.SetDescription("Manage storage drives attached to desktops.");
  286. drive.AddCommand<DesktopDriveAddCommand>("add").WithDescription("Add a drive to a desktop.");
  287. drive.AddCommand<DesktopDriveSetCommand>("set").WithDescription("Update a desktop drive.");
  288. drive.AddCommand<DesktopDriveRemoveCommand>("del")
  289. .WithDescription("Remove a drive from a desktop.");
  290. });
  291. // GPUs
  292. desktops.AddBranch("gpu", gpu =>
  293. {
  294. gpu.SetDescription("Manage GPUs attached to desktops.");
  295. gpu.AddCommand<DesktopGpuAddCommand>("add").WithDescription("Add a GPU to a desktop.");
  296. gpu.AddCommand<DesktopGpuSetCommand>("set").WithDescription("Update a desktop GPU.");
  297. gpu.AddCommand<DesktopGpuRemoveCommand>("del").WithDescription("Remove a GPU from a desktop.");
  298. });
  299. // NICs
  300. desktops.AddBranch("nic", nic =>
  301. {
  302. nic.SetDescription("Manage network interface cards (NICs) for desktops.");
  303. nic.AddCommand<DesktopNicAddCommand>("add").WithDescription("Add a NIC to a desktop.");
  304. nic.AddCommand<DesktopNicSetCommand>("set").WithDescription("Update a desktop NIC.");
  305. nic.AddCommand<DesktopNicRemoveCommand>("del").WithDescription("Remove a NIC from a desktop.");
  306. });
  307. });
  308. // ----------------------------
  309. // Laptops
  310. // ----------------------------
  311. config.AddBranch("Laptops", Laptops =>
  312. {
  313. Laptops.SetDescription("Manage Laptop computers and their components.");
  314. // CRUD
  315. Laptops.AddCommand<LaptopAddCommand>("add").WithDescription("Add a new Laptop.");
  316. Laptops.AddCommand<LaptopGetCommand>("list").WithDescription("List all Laptops.");
  317. Laptops.AddCommand<LaptopGetByNameCommand>("get").WithDescription("Retrieve a Laptop by name.");
  318. Laptops.AddCommand<LaptopDescribeCommand>("describe")
  319. .WithDescription("Show detailed information about a Laptop.");
  320. Laptops.AddCommand<LaptopDeleteCommand>("del").WithDescription("Delete a Laptop from the inventory.");
  321. Laptops.AddCommand<LaptopReportCommand>("summary")
  322. .WithDescription("Show a summarized hardware report for all Laptops.");
  323. Laptops.AddCommand<LaptopTreeCommand>("tree")
  324. .WithDescription("Display the dependency tree for a Laptop.");
  325. // CPU
  326. Laptops.AddBranch("cpu", cpu =>
  327. {
  328. cpu.SetDescription("Manage CPUs attached to Laptops.");
  329. cpu.AddCommand<LaptopCpuAddCommand>("add").WithDescription("Add a CPU to a Laptop.");
  330. cpu.AddCommand<LaptopCpuSetCommand>("set").WithDescription("Update a Laptop CPU.");
  331. cpu.AddCommand<LaptopCpuRemoveCommand>("del").WithDescription("Remove a CPU from a Laptop.");
  332. });
  333. // Drives
  334. Laptops.AddBranch("drive", drive =>
  335. {
  336. drive.SetDescription("Manage storage drives attached to Laptops.");
  337. drive.AddCommand<LaptopDriveAddCommand>("add").WithDescription("Add a drive to a Laptop.");
  338. drive.AddCommand<LaptopDriveSetCommand>("set").WithDescription("Update a Laptop drive.");
  339. drive.AddCommand<LaptopDriveRemoveCommand>("del").WithDescription("Remove a drive from a Laptop.");
  340. });
  341. // GPUs
  342. Laptops.AddBranch("gpu", gpu =>
  343. {
  344. gpu.SetDescription("Manage GPUs attached to Laptops.");
  345. gpu.AddCommand<LaptopGpuAddCommand>("add").WithDescription("Add a GPU to a Laptop.");
  346. gpu.AddCommand<LaptopGpuSetCommand>("set").WithDescription("Update a Laptop GPU.");
  347. gpu.AddCommand<LaptopGpuRemoveCommand>("del").WithDescription("Remove a GPU from a Laptop.");
  348. });
  349. });
  350. // ----------------------------
  351. // Services
  352. // ----------------------------
  353. config.AddBranch("services", service =>
  354. {
  355. service.SetDescription("Manage services and their configurations.");
  356. service.AddCommand<ServiceReportCommand>("summary")
  357. .WithDescription("Show a summary report for all services.");
  358. service.AddCommand<ServiceAddCommand>("add").WithDescription("Add a new service.");
  359. service.AddCommand<ServiceGetCommand>("list").WithDescription("List all services.");
  360. service.AddCommand<ServiceGetByNameCommand>("get").WithDescription("Retrieve a service by name.");
  361. service.AddCommand<ServiceDescribeCommand>("describe")
  362. .WithDescription("Show detailed information about a service.");
  363. service.AddCommand<ServiceSetCommand>("set").WithDescription("Update properties of a service.");
  364. service.AddCommand<ServiceDeleteCommand>("del").WithDescription("Delete a service.");
  365. service.AddCommand<ServiceSubnetsCommand>("subnets")
  366. .WithDescription("List subnets associated with a service, optionally filtered by CIDR.");
  367. });
  368. });
  369. }
  370. private static int HandleException(Exception ex, ITypeResolver? arg2)
  371. {
  372. switch (ex)
  373. {
  374. case ValidationException ve:
  375. AnsiConsole.MarkupLine($"[yellow]Validation error:[/] {ve.Message}");
  376. return 2;
  377. case ConflictException ce:
  378. AnsiConsole.MarkupLine($"[red]Conflict:[/] {ce.Message}");
  379. return 3;
  380. case NotFoundException ne:
  381. AnsiConsole.MarkupLine($"[red]Not found:[/] {ne.Message}");
  382. return 4;
  383. case CommandParseException pe:
  384. if (_showingHelp) return 1; // suppress errors during help lookup
  385. AnsiConsole.MarkupLine($"[red]Invalid command:[/] {pe.Message}");
  386. if (pe.Pretty != null) AnsiConsole.Write(pe.Pretty);
  387. ShowContextualHelp();
  388. return 1;
  389. case CommandRuntimeException re:
  390. if (_showingHelp) return 1;
  391. AnsiConsole.MarkupLine($"[red]Error:[/] {re.Message}");
  392. if (re.Pretty != null) AnsiConsole.Write(re.Pretty);
  393. ShowContextualHelp();
  394. return 1;
  395. default:
  396. AnsiConsole.MarkupLine("[red]Unexpected error occurred.[/]");
  397. AnsiConsole.WriteException(ex, ExceptionFormats.ShortenEverything);
  398. return 99;
  399. }
  400. }
  401. private static bool _showingHelp;
  402. private static void ShowContextualHelp()
  403. {
  404. if (_lastArgs == null || _app == null || _showingHelp) return;
  405. _showingHelp = true;
  406. try
  407. {
  408. // Extract command path (args before any --flags)
  409. var commandPath = _lastArgs.TakeWhile(a => !a.StartsWith("-")).ToList();
  410. // Try progressively shorter command paths until --help succeeds
  411. while (commandPath.Count > 0)
  412. {
  413. var helpArgs = commandPath.Append("--help").ToArray();
  414. AnsiConsole.WriteLine();
  415. var result = _app.Run(helpArgs);
  416. if (result == 0) return;
  417. commandPath.RemoveAt(commandPath.Count - 1);
  418. }
  419. }
  420. finally
  421. {
  422. _showingHelp = false;
  423. }
  424. }
  425. }