|
|
@@ -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}";
|