Просмотр исходного кода

extends Help command to list all details

Dalibor Votruba 4 лет назад
Родитель
Сommit
964cf591e4

+ 77 - 55
Common/qdr.fnd.core.qconsole/Command/Defaults/CmdHelp.cs

@@ -59,6 +59,17 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Defaults
                 {
                     writer.WriteLine($"To view more info for specific command type {Name} <{GetArgument(Constants.Commands.Help.ArgCommandName.Code).Hint}>");
                 }
+
+
+                if (GetArgumentValueOrDefault<bool>(Constants.Commands.Help.ArgFlagAll.Code))
+                {
+                    foreach (var command in Engine.Commands)
+                    {
+                        ShowCommandHelp(command);
+                        WriteInfo("---");
+                    }
+                }
+
             }
         
             else
@@ -67,60 +78,7 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Defaults
                 var command = Engine.GetCommand(argument.Value.AsString());
                 if (command == null)
                     throw new Exception($"Unkonwn command '{argument.Value.AsString()}'");
-                using (var writer = new ConsoleWriter(ConsoleColor.Green))
-                {
-                    using (var writerWhite = new ConsoleWriter(ConsoleColor.White))
-                    {
-                        writer.Write($"Command: \t");
-                        writerWhite.WriteLine(command.Name);
-                        writer.Write($"Description: \t");
-                        writerWhite.WriteLine(command.Description);
-                        writer.Write($"Parameters: \t");
-                        writerWhite.WriteLine((command.Arguments.Length == 0 ? "none" : string.Empty));
-                        foreach (var arg in command.Arguments.OrderBy(x => x.IsPositional() ? 0 : 1))
-                        {
-                            var optional = arg.IsMandatory ? "Mandatory." : "Optional.";
-                            var argumentName = arg.IsPositional()
-                                ? $"<{arg.Code}>"
-                                : $"{Engine.Configuration.CharacterNamedArgumentSeparator}{arg.Code}";
-                            writer.WriteLine($"{argumentName}\t{optional}{arg.Description}");
-                        }
-
-                        var usage = new StringBuilder();
-                        writer.WriteLine();
-                        writer.WriteLine("Usage:");
-                        writer.Write($"\t{Engine.Configuration.CharacterLineIntroduce}");
-                        if (string.IsNullOrEmpty(command.CustomUsage))
-                        {
-                            usage.Append(command.CustomUsage).AppendLine();
-                        }
-                        else
-                        {
-                            usage.Append(command.Name);
-                            foreach (var arg in command.Arguments.OrderBy(x => x.IsPositional() ? 0 : 1))
-                            {
-                                usage.Append(" ");
-                                usage.Append(GetArgumentEntryAsDescription(arg));
-                            }
-                        }
-
-                        writerWhite.WriteLine(usage.ToString());
-
-                        if (!string.IsNullOrEmpty(command.Notes))
-                        {
-                            writer.WriteLine();
-                            writer.Write($"Notes: \t");
-                            writer.Write($"\t{command.Notes}");
-                        }
-
-                        if (!string.IsNullOrEmpty(command.Examples))
-                        {
-                            writer.WriteLine();
-                            writer.Write($"Examples: \t");
-                            writer.Write($"\t{command.Examples}");
-                        }
-                    }
-                }
+                ShowCommandHelp(command);
 
             }
             return new Result();
@@ -137,13 +95,77 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Defaults
                     Constants.Commands.Help.ArgCommandName.Hint,
                     TypeValuesEnum.String,
                     string.Empty,
-                    false)
+                    false),
+                new FlagArgument(Constants.Commands.Help.ArgFlagAll.Code,
+                    Constants.Commands.Help.ArgFlagAll.Description,
+                    Constants.Commands.Help.ArgFlagAll.Hint,
+                    false
+                    )
             });
             return result;
         }
         #endregion
 
         #region *** Private Operations ***
+
+        private void ShowCommandHelp(AbstractCommand command)
+        {
+            using (var writer = new ConsoleWriter(ConsoleColor.Green))
+            {
+                using (var writerWhite = new ConsoleWriter(ConsoleColor.White))
+                {
+                    writer.Write($"Command: \t");
+                    writerWhite.WriteLine(command.Name);
+                    writer.Write($"Description: \t");
+                    writerWhite.WriteLine(command.Description);
+                    writer.Write($"Parameters: \t");
+                    writerWhite.WriteLine((command.Arguments.Length == 0 ? "none" : string.Empty));
+                    foreach (var arg in command.Arguments.OrderBy(x => x.IsPositional() ? 0 : 1))
+                    {
+                        var optional = arg.IsMandatory ? "Mandatory." : "Optional.";
+                        var argumentName = arg.IsPositional()
+                            ? $"<{arg.Code}>"
+                            : $"{Engine.Configuration.CharacterNamedArgumentSeparator}{arg.Code}";
+                        writer.WriteLine($"{argumentName}\t{optional}{arg.Description}");
+                    }
+
+                    var usage = new StringBuilder();
+                    writer.WriteLine();
+                    writer.WriteLine("Usage:");
+                    writer.Write($"\t{Engine.Configuration.CharacterLineIntroduce}");
+                    if (!string.IsNullOrEmpty(command.CustomUsage))
+                    {
+                        usage.Append(command.CustomUsage).AppendLine();
+                    }
+                    else
+                    {
+                        usage.Append(command.Name);
+                        foreach (var arg in command.Arguments.OrderBy(x => x.IsPositional() ? 0 : 1))
+                        {
+                            usage.Append(" ");
+                            usage.Append(GetArgumentEntryAsDescription(arg));
+                        }
+                    }
+
+                    writerWhite.WriteLine(usage.ToString());
+
+                    if (!string.IsNullOrEmpty(command.Notes))
+                    {
+                        writer.WriteLine();
+                        writer.Write($"Notes: \t");
+                        writer.Write($"\t{command.Notes}");
+                    }
+
+                    if (!string.IsNullOrEmpty(command.Examples))
+                    {
+                        writer.WriteLine();
+                        writer.Write($"Examples: \t");
+                        writer.Write($"\t{command.Examples}");
+                    }
+                }
+            }
+        }
+
         private string GetArgumentEntryAsDescription(AbstractArgument arg)
         {
             var argumentName = $"{Engine.Configuration.CharacterNamedArgumentSeparator}{arg.Code}";

+ 7 - 0
Common/qdr.fnd.core.qconsole/Constants.cs

@@ -77,6 +77,13 @@
                     public const string Hint = "command_name";
                     public const string Description = "Name of command to list specification.";
                 }
+
+                public static class ArgFlagAll
+                {
+                    public const string Code = "all";
+                    public const string Hint = "show_all";
+                    public const string Description = "Flag if set dump all commands help.";
+                }
             }
 
             public static class Exit

+ 2 - 4
Console/Commands/Base/AbstractListScopedCommand.cs

@@ -18,7 +18,6 @@ namespace BO.Console.Commands.Base
         #endregion
 
         #region *** Private Fields ***
-        private string _scopeList;
 
         protected TScopeEnum Scope { get; private set; }
         #endregion
@@ -26,7 +25,6 @@ namespace BO.Console.Commands.Base
         #region *** Constructors ***
         protected AbstractListScopedCommand(Engine engine) : base(engine)
         {
-            _scopeList = string.Join(", ", Enum.GetNames(typeof(TScopeEnum)));
         }
         #endregion
 
@@ -39,7 +37,7 @@ namespace BO.Console.Commands.Base
             var scope = GetArgumentValueOrDefault<string>(CS_ARG_NAME_SCOPE);
             if (!Enum.TryParse(typeof(TScopeEnum), scope, true, out var res))
                 throw new ArgumentException(
-                    $"Argument {Engine.Configuration.CharacterNamedArgumentSeparator}{CS_ARG_NAME_SCOPE} invalid value. Must be one of: {_scopeList} !",
+                    $"Argument {Engine.Configuration.CharacterNamedArgumentSeparator}{CS_ARG_NAME_SCOPE} invalid value. Must be one of: {string.Join(", ", Enum.GetNames(typeof(TScopeEnum)))} !",
                     nameof(CS_ARG_NAME_SCOPE));
             Scope = (TScopeEnum)res;
         }
@@ -47,7 +45,7 @@ namespace BO.Console.Commands.Base
         protected override IEnumerable<AbstractArgument> OnSetupArguments()
         {
             var args =  new List<AbstractArgument>(base.OnSetupArguments());
-            args.Add(new NamedArgument(CS_ARG_NAME_SCOPE, string.Format(CS_ARG_DESC_SCOPE, _scopeList), CS_ARG_HINT_SCOPE,TypeValuesEnum.String,string.Empty,true));
+            args.Add(new NamedArgument(CS_ARG_NAME_SCOPE, string.Format(CS_ARG_DESC_SCOPE, string.Join(", ", Enum.GetNames(typeof(TScopeEnum)))), CS_ARG_HINT_SCOPE,TypeValuesEnum.String,string.Empty,true));
             return args;
         }
         #endregion

+ 1 - 1
Console/Commands/Base/AbstractPostCommand.cs

@@ -124,7 +124,7 @@ namespace BO.Console.Commands.Base
         protected override IEnumerable<AbstractArgument> OnSetupArguments()
         {
             var args = base.OnSetupArguments().ToList();
-            args.Add(new NamedArgument(CS_ARG_NAME_IN , CS_ARG_DESC_IN, CS_ARG_HINT_IN, TypeValuesEnum.String, string.Empty,true));
+            args.Add(new NamedArgument(CS_ARG_NAME_IN , string.Format(CS_ARG_DESC_IN, typeof(TData).Name), CS_ARG_HINT_IN, TypeValuesEnum.String, string.Empty,true));
             args.Add(new FlagArgument(CS_ARG_NAME_LIST , CS_ARG_DESC_LIST, CS_ARG_HINT_LIST,false));
             return args;
         }

+ 1 - 1
Console/Properties/launchSettings.json

@@ -2,7 +2,7 @@
   "profiles": {
     "Console": {
       "commandName": "Project",
-      "commandLineArgs": "version -local"
+      "commandLineArgs": "help -all"
     }
   }
 }