public async Task Run(XConsole xc)
 {
     try
     {
         xc.AskForInput(this, "Enter command name: ");
         using (var scope = xc.WebHost.Services.CreateScope())
         {
             string command      = Console.ReadLine();
             var    commandClass = xc.FindCommand(command);
             if (commandClass != null)
             {
                 try
                 {
                     var commandInstance = xc.CreateCommandInstance(commandClass);
                     xc.WriteHelp(commandInstance);
                 }
                 catch (Exception)
                 {
                     xc.WriteError(this, $"Unable to display help for {command}");
                 }
             }
             else
             {
                 xc.WriteWarning(this, "Command not found.");
             }
         }
     }
     catch (Exception ex)
     {
         xc.WriteException(this, ex);
     }
 }
Beispiel #2
0
        public async Task Run(XConsole xc)
        {
            try
            {
                xc.AskForInput(this, "Filter by (leave blank for all): ", false);
                var           filter = Console.ReadLine();
                List <string> list;
                if (string.IsNullOrEmpty(filter))
                {
                    list = xc.CommandList;
                }
                else
                {
                    filter = filter.Replace("-", "").ToLower();
                    list   = xc.CommandList.Where(x => x.ToLower().Contains(filter)).ToList();
                }
                xc.WriteInfo(this, $"Total {list.Count} commands found.");

                if (list.Count > 0)
                {
                    var table = xc.CreateTable(new string[] { "Command", "Description" });
                    foreach (string className in list)
                    {
                        try
                        {
                            var instance = xc.CreateCommandInstance(className);
                            table.AddRow(new[] { instance.GetName(), instance.GetDescription() });
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                    //table.Write(ConsoleTables.Format.Alternative);
                    xc.WriteTable(table);
                }
            }
            catch (Exception ex)
            {
                xc.WriteException(this, ex);
            }
        }