CliBootstrap.cs 25 KB

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