Преглед изворни кода

QConsole v1.0.0.2

New
 - Allows to use more asseblies in CommandDefinitionAssebmly
 - Add DisableDefaultCommands to StartupConfiguration to hide default commands
 - Add WaitOnKeyInNonInteractiveMode to wait on key at the end of the non-interactive process
Fix
 - Flag arguments behaviours
 - NonIteractive usage
Dalibor Votruba пре 6 година
родитељ
комит
55f44280d7

+ 5 - 3
QConsole/QConsole.DevBench/Program.cs

@@ -13,10 +13,12 @@ namespace Quadarax.Foundation.QConsole.DevBench
             //var input = "-c:\"fofo aa\" -new:12 -b:True";
             //var result = Split(input, "\"", new[] {" ", "-"});
             //Console.ReadLine();
-            var config = new StartupConfiguration("MyTestConsole", Version.Parse("1.0.0")).EnableDebugMode();
-            config.CommandDefinitionAssebmly = Assembly.GetEntryAssembly();
+            var config = new StartupConfiguration("MyTestConsole", Version.Parse("1.0.0"));
+            config.AllowInteractive = false;
+            config.CommandDefinitionAssebmly = new Assembly[]{Assembly.GetEntryAssembly()};
+            config.DisableDefaultCommands = true;
 
-            var console = new Engine(config, args);
+             var console = new Engine(config, args);
             console.Start();
 
             Console.WriteLine("Press any key to exit (external wait)...");

+ 4 - 0
QConsole/QConsole/Command/Base/AbstractCommand.cs

@@ -47,6 +47,7 @@ namespace Quadarax.Foundation.QConsole.Command.Base
                 foreach (var arg in Arguments)
                     arg.SetValueAsDefault();
                 ParseInput(input);
+
                 var result = OnExecute();
                 result = EndExecute(result);
                 
@@ -201,6 +202,9 @@ namespace Quadarax.Foundation.QConsole.Command.Base
         protected virtual IEnumerable<AbstractArgument> OnSetupArguments()
         {
             return new AbstractArgument[0];
+            //{
+            //    new FlagArgument(Constants.Arguments.General.DebugMode.Code, Constants.Arguments.General.DebugMode.Description, Constants.Arguments.General.DebugMode.Hint, true), 
+            //};
         }
 
         

+ 13 - 2
QConsole/QConsole/Command/Defaults/CmdHelp.cs

@@ -29,6 +29,15 @@ namespace Quadarax.Foundation.QConsole.Command.Defaults
         {
             if (!GetArgument(Constants.Commands.Help.ArgCommandName.Code).Value.HasValue)
             {
+                if (!Engine.Configuration.IsConsoleDebug)
+                {
+                    using (var writer = new ConsoleWriter(ConsoleColor.White))
+                    {
+                        writer.WriteLine(
+                            "To enable debug mode - more verbosity - use argument \"-dbg\" at the end of line.");
+                    }
+                }
+
                 using (var writer = new ConsoleWriter(ConsoleColor.Yellow))
                 {
                     writer.WriteLine("Console commands list:");
@@ -95,7 +104,8 @@ namespace Quadarax.Foundation.QConsole.Command.Defaults
 
         protected override IEnumerable<AbstractArgument> OnSetupArguments()
         {
-            return new AbstractArgument[]
+            var result = base.OnSetupArguments().ToList();
+            result.AddRange( new AbstractArgument[]
             {
                 new OrdinalArgument(0, true, 
                     Constants.Commands.Help.ArgCommandName.Code,
@@ -104,7 +114,8 @@ namespace Quadarax.Foundation.QConsole.Command.Defaults
                     TypeValuesEnum.String,
                     string.Empty,
                     false)
-            };
+            });
+            return result;
         }
         #endregion
 

+ 13 - 4
QConsole/QConsole/Configuration/StartupConfiguration.cs

@@ -70,9 +70,19 @@ namespace Quadarax.Foundation.QConsole.Configuration
         public bool AllowPreset { get; set; }
 
         /// <summary>
-        /// Defines assembly where custom commands are defined (in case explicit command definition).
+        /// Defines assembly list where custom commands are defined (in case explicit command definition).
         /// </summary>
-        public Assembly CommandDefinitionAssebmly { get; set; }
+        public Assembly[] CommandDefinitionAssebmly { get; set; }
+
+        /// <summary>
+        /// Defines if default (build-in) commands CLEAR,EXIT,PRINT,SELECTION will be disabled (hidden).
+        /// </summary>
+        public bool DisableDefaultCommands { get; set; }
+
+        /// <summary>
+        /// Defines if waits on key at the end of process in non-interactive mode (inline mode)
+        /// </summary>
+        public bool WaitOnKeyInNonInteractiveMode { get; set; }
 
         public bool IsConsoleDebug {
             get
@@ -139,8 +149,7 @@ namespace Quadarax.Foundation.QConsole.Configuration
             AllowInteractive = Defaults.Console.InteractiveAllowed;
             AllowPreset = Defaults.Console.PresetAllowed;
             IsConsoleDebug = Defaults.Console.ConsoleDebugMode;
-
-
+            DisableDefaultCommands = Defaults.Console.DisableDefaultCommands;
 
         }
         #endregion

+ 6 - 0
QConsole/QConsole/Constants.cs

@@ -1,10 +1,16 @@
 using System;
+using System.Security.Permissions;
 
 namespace Quadarax.Foundation.QConsole
 {
     public static class Constants
     {
 
+        public static class Console
+        {
+            public const string DebugModeExplicitArg = "-dbg";
+        }
+
         public static class Arguments
         {
             public static class Selection

+ 1 - 0
QConsole/QConsole/Defaults.cs

@@ -14,6 +14,7 @@ namespace Quadarax.Foundation.QConsole
             internal const bool PresetAllowed = false;
             internal const bool ConsoleDebugMode = false;
             internal const ConsoleColor ConsoleDebugForeColor = ConsoleColor.DarkGray;
+            internal const bool DisableDefaultCommands = false;
         }
 
         internal class Formats

+ 21 - 3
QConsole/QConsole/Engine.cs

@@ -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
             {

+ 2 - 2
QConsole/QConsole/Properties/AssemblyInfo.cs

@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.1")]
-[assembly: AssemblyFileVersion("1.0.0.1")]
+[assembly: AssemblyVersion("1.0.0.2")]
+[assembly: AssemblyFileVersion("1.0.0.2")]

+ 1 - 1
QConsole/QConsole/QDR.FND.QConsole.nuspec

@@ -2,7 +2,7 @@
 <package>
   <metadata>
     <id>Quadarax.Foundation.QConsole</id>
-    <version>1.0.0.1</version>
+    <version>1.0.0.2</version>
     <title>Quadarax.Foundation.QConsole</title>
     <authors>Dalibor Votruba, Quadarax</authors>
     <owners>Dalibor Votruba</owners>

+ 10 - 1
QConsole/QConsole/ReleaseNote.txt

@@ -1,3 +1,12 @@
-12.1.2019 v.1.0.0.1
+23.12.2019 v.1.0.0.2
+New
+ - Allows to use more asseblies in CommandDefinitionAssebmly
+ - Add DisableDefaultCommands to StartupConfiguration to hide default commands
+ - Add WaitOnKeyInNonInteractiveMode to wait on key at the end of the non-interactive process
+Fix
+ - Flag arguments behaviours
+ - NonIteractive usage
+
+1.12.2019 v.1.0.0.1
 New
  - Inline command support for noninteractive usage