|
|
@@ -4,6 +4,7 @@ using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using Quadarax.Foundation.QConsole.Attributes;
|
|
|
using Quadarax.Foundation.QConsole.Command.Base;
|
|
|
+using Quadarax.Foundation.QConsole.Command.Defaults;
|
|
|
using Quadarax.Foundation.QConsole.Configuration;
|
|
|
|
|
|
namespace Quadarax.Foundation.QConsole
|
|
|
@@ -29,9 +30,20 @@ namespace Quadarax.Foundation.QConsole
|
|
|
public Engine(StartupConfiguration configuration, string[] args)
|
|
|
{
|
|
|
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
|
|
|
+
|
|
|
if (args == null)
|
|
|
args = new string[0];
|
|
|
|
|
|
+ // Ensure if debug mode -> Enable debug mode and remove explicit argument
|
|
|
+ if (args.Any(x => x.Trim().ToLower() == Constants.Console.DebugModeExplicitArg))
|
|
|
+ {
|
|
|
+ configuration.EnableDebugMode();
|
|
|
+ var newArgs = new List<string>(args);
|
|
|
+ newArgs.Remove(Constants.Console.DebugModeExplicitArg);
|
|
|
+ args = newArgs.ToArray();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
WriteDebugInfo($"Console '{_configuration.ConsoleName}' initialization started.");
|
|
|
WriteDebugInfo($"Engine assembly version '{Assembly.GetExecutingAssembly().GetName().Version}'.");
|
|
|
WriteDebugInfo($"IsInitFromXml is set to '{_configuration.IsInitFromXml}'.");
|
|
|
@@ -67,7 +79,7 @@ namespace Quadarax.Foundation.QConsole
|
|
|
while (!_isExitSignal)
|
|
|
{
|
|
|
var input = string.Empty;
|
|
|
- if (commandLineArguments.Length == 0)
|
|
|
+ if (commandLineArguments.Length == 0 && Configuration.AllowInteractive)
|
|
|
{
|
|
|
// interactive command entry
|
|
|
writer.Write(_configuration.CharacterLineIntroduce);
|
|
|
@@ -197,11 +209,17 @@ namespace Quadarax.Foundation.QConsole
|
|
|
}
|
|
|
private IEnumerable<Type> GetTypesWithHelpAttribute(Attribute attribute)
|
|
|
{
|
|
|
- var defaultTypes = Assembly.GetExecutingAssembly().GetTypes().Where(type => type.GetCustomAttributes(attribute.GetType(), true).Length > 0).ToList();
|
|
|
+ var defaultTypes = _configuration.DisableDefaultCommands ?
|
|
|
+ new List<Type>(new []{typeof(CmdHelp)}):
|
|
|
+ Assembly.GetExecutingAssembly().GetTypes().Where(type => type.GetCustomAttributes(attribute.GetType(), true).Length > 0).ToList();
|
|
|
+
|
|
|
var customTypes = new List<Type>();
|
|
|
if (_configuration.CommandDefinitionAssebmly != null)
|
|
|
{
|
|
|
- customTypes = _configuration.CommandDefinitionAssebmly.GetTypes().Where(type => type.GetCustomAttributes(attribute.GetType(), true).Length > 0).ToList();
|
|
|
+ foreach (var assembly in _configuration.CommandDefinitionAssebmly)
|
|
|
+ {
|
|
|
+ customTypes.AddRange(assembly.GetTypes().Where(type => type.GetCustomAttributes(attribute.GetType(), true).Length > 0).ToArray());
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|