From 70bf55cb93ae754bae6ed7b35306f2c5cb4c1d8b Mon Sep 17 00:00:00 2001 From: franck gaspoz Date: Sun, 28 Feb 2021 18:48:11 +0100 Subject: [PATCH] release 1.0.9 fix get vars exception when convert from null + fix comments + integrated xml code spec for intellisense --- OrbitalShell-CLI/OrbitalShell-CLI.csproj | 5 +- OrbitalShell-CLI/Program.cs | 4 +- .../Scripts/publish-kernel-packages.sh | 12 +++-- OrbitalShell-CLI/ServicesInitializer.cs | 2 + OrbitalShell-CLI/Shell.cs | 41 ---------------- OrbitalShell-CLI/ShellStartup.cs | 47 +++++++++++++++++++ OrbitalShell-ConsoleApp/App.cs | 2 +- .../Component/Console/ANSI.cs | 18 +++---- .../Component/Console/TextColor.cs | 2 +- .../Component/EchoDirective/EchoDirectives.cs | 24 +++++----- .../NonRecursiveFunctionGrammarParser.cs | 2 +- .../OrbitalShell-ConsoleApp.csproj | 5 +- OrbitalShell-Kernel-Commands/ModuleInfo.cs | 7 ++- .../OrbitalShell-Kernel-Commands.csproj | 5 +- .../Processor/CommandEvaluationContext.cs | 2 +- .../Processor/CommandLineProcessor.cs | 7 ++- .../Processor/ICommandLineProcessor.cs | 2 + .../CommandLine/Reader/CommandLineReader.cs | 16 ++----- .../Component/Shell/Hook/HookManager.cs | 2 +- .../Component/Shell/IShellStartup.cs | 7 +++ .../Shell/Variable/ShellEnvironment.cs | 28 ++++++++--- .../Component/Shell/Variable/Variables.cs | 9 ++-- OrbitalShell-Kernel/ModuleInfo.cs | 7 ++- .../OrbitalShell-Kernel.csproj | 5 +- 24 files changed, 148 insertions(+), 113 deletions(-) delete mode 100644 OrbitalShell-CLI/Shell.cs create mode 100644 OrbitalShell-CLI/ShellStartup.cs create mode 100644 OrbitalShell-Kernel/Component/Shell/IShellStartup.cs diff --git a/OrbitalShell-CLI/OrbitalShell-CLI.csproj b/OrbitalShell-CLI/OrbitalShell-CLI.csproj index 23ec037c..56054b44 100644 --- a/OrbitalShell-CLI/OrbitalShell-CLI.csproj +++ b/OrbitalShell-CLI/OrbitalShell-CLI.csproj @@ -17,8 +17,8 @@ Orbital Shell This is the Orbital Shell CLI binaries for any plateform (having dotnet) and also self-contained apps for common runtimes environments (win-x64,linux-x64,linux-musl-x64,linux-arm,linux-arm64). Orbital Shell is a command shell based inspired by bash and POSIX recommendations, coded in C# .Net Core. (c) 2020 Licence MIT - 1.0.8 - 1.0.8 + 1.0.9 + 1.0.9 initial stable release (milestone 1) assets\robotazteque.ico @@ -54,6 +54,7 @@ true false bin/Debug/net5.0/orbsh.xml + 1701;1702;1591;1572;1573 diff --git a/OrbitalShell-CLI/Program.cs b/OrbitalShell-CLI/Program.cs index 870f1785..9cebd99a 100644 --- a/OrbitalShell-CLI/Program.cs +++ b/OrbitalShell-CLI/Program.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using OrbitalShell.Component.Shell; namespace OrbitalShell { @@ -18,7 +19,8 @@ static int Main(string[] args) var scope = App.Host.Services.CreateScope(); si.ScopedServiceProvider = scope.ServiceProvider; - var returnCode = Shell.Startup(scope.ServiceProvider,args); + var shellStartup = scope.ServiceProvider.GetRequiredService(); + var returnCode = shellStartup.Startup(args); App.Host.RunAsync().Wait(); diff --git a/OrbitalShell-CLI/Scripts/publish-kernel-packages.sh b/OrbitalShell-CLI/Scripts/publish-kernel-packages.sh index 2b8f8967..4751c73e 100644 --- a/OrbitalShell-CLI/Scripts/publish-kernel-packages.sh +++ b/OrbitalShell-CLI/Scripts/publish-kernel-packages.sh @@ -9,10 +9,14 @@ echo "(b=darkgreen,f=black) build/publish orbital shell kernel packages (rdc)" echo "(b=darkgreen,f=black) " echo proj -dotnet build OrbitalShell.sln -c Debug +#dotnet build OrbitalShell.sln -c Release -nuget-push OrbitalShell-ConsoleApp/bin/Debug/OrbitalShell-ConsoleApp.$version $key -nuget-push OrbitalShell-Kernel/bin/Debug/OrbitalShell-Kernel.$version $key -nuget-push OrbitalShell-Kernel-Commands/bin/Debug/OrbitalShell-Kernel-Commands.$version $key +#nuget-push OrbitalShell-ConsoleApp/bin/Debug/OrbitalShell-ConsoleApp.$version $key +#nuget-push OrbitalShell-Kernel/bin/Debug/OrbitalShell-Kernel.$version $key +#nuget-push OrbitalShell-Kernel-Commands/bin/Debug/OrbitalShell-Kernel-Commands.$version $key + +nuget-push OrbitalShell-ConsoleApp/bin/Release/OrbitalShell-ConsoleApp.$version $key +nuget-push OrbitalShell-Kernel/bin/Release/OrbitalShell-Kernel.$version $key +nuget-push OrbitalShell-Kernel-Commands/bin/Release/OrbitalShell-Kernel-Commands.$version $key echo "(b=darkgreen,f=yellow) Done. (rdc)" diff --git a/OrbitalShell-CLI/ServicesInitializer.cs b/OrbitalShell-CLI/ServicesInitializer.cs index 6850a5ff..2d54d3da 100644 --- a/OrbitalShell-CLI/ServicesInitializer.cs +++ b/OrbitalShell-CLI/ServicesInitializer.cs @@ -57,6 +57,8 @@ public void InitializeServices(IHostBuilder hostBuilder) serviceProvider.GetRequiredService()); return clr; }) + .AddScoped + () ); } } diff --git a/OrbitalShell-CLI/Shell.cs b/OrbitalShell-CLI/Shell.cs deleted file mode 100644 index b036ba3b..00000000 --- a/OrbitalShell-CLI/Shell.cs +++ /dev/null @@ -1,41 +0,0 @@ -using OrbitalShell.Component.CommandLine.Reader; -using OrbitalShell.Component.CommandLine.Processor; -using OrbitalShell.Component.Console; -using OrbitalShell.Component.Shell; -using Microsoft.Extensions.DependencyInjection; -using System; - -namespace OrbitalShell -{ - public class Shell - { - public static int Startup(IServiceProvider serviceProvider,string[] args) - { - var cons = serviceProvider.GetRequiredService(); - - // 2. build a clp - - var clp = serviceProvider.GetRequiredService(); - - clp.SetArgs(args); - - // 3. build a clr associated to the clp - - var clr = serviceProvider.GetRequiredService(); - - // 4 . prepare console - - cons.Out.Echo(ANSI.RIS); - cons.Out.ClearScreen(); - - // 5. invoke a shell initializer associated to the clp - - var shellInitializer = new ShellInitializer(clp); - shellInitializer.Run(clp.CommandEvaluationContext); - - // 6. starts an interactive shell - - return clr.ReadCommandLine(); - } - } -} diff --git a/OrbitalShell-CLI/ShellStartup.cs b/OrbitalShell-CLI/ShellStartup.cs new file mode 100644 index 00000000..427b3dc8 --- /dev/null +++ b/OrbitalShell-CLI/ShellStartup.cs @@ -0,0 +1,47 @@ +using OrbitalShell.Component.CommandLine.Reader; +using OrbitalShell.Component.CommandLine.Processor; +using OrbitalShell.Component.Console; +using OrbitalShell.Component.Shell; +using System; + +namespace OrbitalShell +{ + public class ShellStartup : IShellStartup + { + IConsole _cons; + ICommandLineProcessor _clp; + ICommandLineReader _clr; + + public ShellStartup( + IServiceProvider serviceProvider, + IConsole console, + ICommandLineProcessor commandLineProcessor, + ICommandLineReader commandLineReader + ) + { + _cons = console; + _clp = commandLineProcessor; + _clr = commandLineReader; + } + + public int Startup( + string[] args) + { + _clp.SetArgs(args); + + // prepare console + + _cons.Out.Echo(ANSI.RIS); + _cons.Out.ClearScreen(); + + // invoke a shell initializer associated to the clp + + var shellInitializer = new ShellInitializer(_clp); + shellInitializer.Run(_clp.CommandEvaluationContext); + + // starts an interactive shell + + return _clr.ReadCommandLine(); + } + } +} diff --git a/OrbitalShell-ConsoleApp/App.cs b/OrbitalShell-ConsoleApp/App.cs index 3cd68711..ccccc492 100644 --- a/OrbitalShell-ConsoleApp/App.cs +++ b/OrbitalShell-ConsoleApp/App.cs @@ -10,8 +10,8 @@ namespace OrbitalShell /// /// console app bootstrap - /// /// + /// /// begin DI init /// public static class App diff --git a/OrbitalShell-ConsoleApp/Component/Console/ANSI.cs b/OrbitalShell-ConsoleApp/Component/Console/ANSI.cs index d8e9ea1b..285513c9 100644 --- a/OrbitalShell-ConsoleApp/Component/Console/ANSI.cs +++ b/OrbitalShell-ConsoleApp/Component/Console/ANSI.cs @@ -380,9 +380,9 @@ public static (SGR_4BitsColors color, bool bright) ParseSGR_4BitsColor(string s) /// 8- 15: high intensity colors (as in ESC [ 90–97 m, see SGR_4BitsColors bright)
/// 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
/// 232-255: grayscale from black to white in 24 steps - /// format is {n},0<=n<=255 + /// format is {n},0<=n<=255 /// - /// {n},0<=n<=255 + /// {n},0<=n<=255 /// ansi seq public static string SGRF8(object o) { @@ -412,9 +412,9 @@ public static string SGRF8(object o) /// /// set foreground color - 24 bits 'true color' (for 16 or 24 bits palette graphic cards) /// parameters are red,green,blue luminosity from 0 to 255 - /// format is: {r}:{g}:{b} 0<=r<=255 0<=g<=255 0<=b<=255 + /// format is: {r}:{g}:{b} 0<=r<=255 0<=g<=255 0<=b<=255 /// - /// {r}:{g}:{b} 0<=r<=255 0<=g<=255 0<=b<=255 + /// {r}:{g}:{b} 0<=r<=255 0<=g<=255 0<=b<=255 /// ansi seq public static string SGRF24(object o) { @@ -465,7 +465,7 @@ public static string SGRB(object o) /// set background color - 8 bits palette (256 colors) /// 0- 7: standard colors (as in ESC [ 30–37 m, see SGR_4BitsColors)
/// 8- 15: high intensity colors (as in ESC [ 90–97 m, see SGR_4BitsColors bright)
- /// 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
+ /// 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 <= r, g, b ≤ 5)
/// 232-255: grayscale from black to white in 24 steps
/// /// palette color index @@ -478,9 +478,9 @@ public static string SGRB(object o) /// 8- 15: high intensity colors (as in ESC [ 90–97 m, see SGR_4BitsColors bright)
/// 16-231: 6 × 6 × 6 cube (216 colors): 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
/// 232-255: grayscale from black to white in 24 steps - /// format is {n},0<=n<=255 + /// format is {n},0<=n<=255 /// - /// {n},0<=n<=255 + /// {n},0<=n<=255 /// ansi seq public static string SGRB8(object o) { @@ -510,9 +510,9 @@ public static string SGRB8(object o) /// /// set background color - 24 bits 'true color' (for 16 or 24 bits palette graphic cards) /// parameters are red,green,blue luminosity from 0 to 255 - /// format is: {r}:{g}:{b} 0<=r<=255 0<=g<=255 0<=b<=255 + /// format is: {r}:{g}:{b} 0<=r<=255 0<=g<=255 0<=b<=255 /// - /// {r}:{g}:{b} 0<=r<=255 0<=g<=255 0<=b<=255 + /// {r}:{g}:{b} 0<=r<=255 0<=g<=255 0<=b<=255 /// ansi seq public static string SGRB24(object o) { diff --git a/OrbitalShell-ConsoleApp/Component/Console/TextColor.cs b/OrbitalShell-ConsoleApp/Component/Console/TextColor.cs index 7ff6786b..b846ef06 100644 --- a/OrbitalShell-ConsoleApp/Component/Console/TextColor.cs +++ b/OrbitalShell-ConsoleApp/Component/Console/TextColor.cs @@ -93,7 +93,7 @@ public static int Parse8BitColor(IConsole console, object c) /// /// parse a 24 bit color /// - /// string of format: r:g:b where 0<=r,g,b<=255 + /// string of format: r:g:b where 0<=r,g,b <255 /// public static (int r,int g,int b) Parse24BitColor(IConsole console, object c) { diff --git a/OrbitalShell-ConsoleApp/Component/EchoDirective/EchoDirectives.cs b/OrbitalShell-ConsoleApp/Component/EchoDirective/EchoDirectives.cs index f0436335..78bb282b 100644 --- a/OrbitalShell-ConsoleApp/Component/EchoDirective/EchoDirectives.cs +++ b/OrbitalShell-ConsoleApp/Component/EchoDirective/EchoDirectives.cs @@ -345,10 +345,8 @@ public enum EchoDirectives /// SGR_RapidBlink, - /// - /// - /// SGR_ReverseVideo, @@ -393,32 +391,32 @@ public enum EchoDirectives SGR_NormalIntensity, /// - /// Set foreground color - 3/4 bits palette mode : SGRF=0<=n<=7[,bright] + /// Set foreground color - 3/4 bits palette mode : SGRF=0<=n<=7[,bright] /// SGRF, /// - /// set foreground color - 8 bits palette (256 colors) : SGRF8=0<=n<=255 + /// set foreground color - 8 bits palette (256 colors) : SGRF8=0<=n<=255 /// SGRF8, /// - /// set foreground color - 24 bits 'true color' : SGRF24=0<=n<=255,0<=n<=255,0<=n<=255 (r,g,b) + /// set foreground color - 24 bits 'true color' : SGRF24=0<=n<=255,0<=n<=255,0<=n<=255 (r,g,b) /// SGRF24, /// - /// Set background color - 3/4 bits palette mode : SGRF=0<=n<=7[,bright] + /// Set background color - 3/4 bits palette mode : SGRF=0<=n<=7[,bright] /// SGRB, /// - /// set background color - 8 bits palette (256 colors) : SGRF8=0<=n<=255 + /// set background color - 8 bits palette (256 colors) : SGRF8=0<=n<=255 /// SGRB8, /// - /// set background color - 24 bits 'true color' : SGRF24=0<=n<=255,0<=n<=255,0<=n<=255 (r,g,b) + /// set background color - 24 bits 'true color' : SGRF24=0<=n<=255,0<=n<=255,0<=n<=255 (r,g,b) /// SGRB24, @@ -457,12 +455,12 @@ public enum EchoDirectives f, /// - /// set foreground from 8 bits palette : f8=0<=n<=255 + /// set foreground from 8 bits palette : f8=0<=n<=255 /// f8, /// - /// set foreground from 24 bits color : f24=r:g:b with 0<=r,g,b<=255 + /// set foreground from 24 bits color : f24=r:g:b with 0<=r,g,b<=255 /// f24, @@ -472,12 +470,12 @@ public enum EchoDirectives b, /// - /// set background from 8 bits palette : b8=0<=n<=255 + /// set background from 8 bits palette : b8=0<=n<=255 /// b8, /// - /// set background from 24 bits color : b24=r:g:b with 0<=r,g,b<=255 + /// set background from 24 bits color : b24=r:g:b with 0<=r,g,b<=255 /// b24, diff --git a/OrbitalShell-ConsoleApp/Component/Parser/NonRecursiveFunctionalGrammar/NonRecursiveFunctionGrammarParser.cs b/OrbitalShell-ConsoleApp/Component/Parser/NonRecursiveFunctionalGrammar/NonRecursiveFunctionGrammarParser.cs index 1ead0f91..ebf14e92 100644 --- a/OrbitalShell-ConsoleApp/Component/Parser/NonRecursiveFunctionalGrammar/NonRecursiveFunctionGrammarParser.cs +++ b/OrbitalShell-ConsoleApp/Component/Parser/NonRecursiveFunctionalGrammar/NonRecursiveFunctionGrammarParser.cs @@ -9,7 +9,7 @@ public class NonRecursiveFunctionGrammarParser #region predefined grammar functions /// - /// ascii<32 && !=27 (ANSI Single Code Function) + /// ascii<32 && !=27 (ANSI Single Code Function) /// public const string SCF = "scf"; diff --git a/OrbitalShell-ConsoleApp/OrbitalShell-ConsoleApp.csproj b/OrbitalShell-ConsoleApp/OrbitalShell-ConsoleApp.csproj index 8c6e09a2..cd213c8e 100644 --- a/OrbitalShell-ConsoleApp/OrbitalShell-ConsoleApp.csproj +++ b/OrbitalShell-ConsoleApp/OrbitalShell-ConsoleApp.csproj @@ -14,8 +14,8 @@ Orbital Shell - ConsoleApp Orbital Shell console application library (c) 2020 Licence MIT - 1.0.8 - 1.0.8 + 1.0.9 + 1.0.9 milestone 1 MIT @@ -49,6 +49,7 @@ true true bin/Debug/net5.0/OrbitalShell-ConsoleApp.xml + 1701;1702;1591;1572;1573 diff --git a/OrbitalShell-Kernel-Commands/ModuleInfo.cs b/OrbitalShell-Kernel-Commands/ModuleInfo.cs index 28db6645..f18588b7 100644 --- a/OrbitalShell-Kernel-Commands/ModuleInfo.cs +++ b/OrbitalShell-Kernel-Commands/ModuleInfo.cs @@ -1,12 +1,11 @@ using OrbitalShell.Component.Shell.Module; using OrbitalShell.Lib; -/// -/// declare a shell module -/// +// declare a shell module + [assembly: ShellModule("OrbitalShell-Kernel-Commands")] [assembly: ModuleTargetPlateform(TargetPlatform.Any)] -[assembly: ModuleShellMinVersion("1.0.8")] +[assembly: ModuleShellMinVersion("1.0.9")] [assembly: ModuleAuthors("Orbital Shell team")] namespace OrbitalShell.Kernel.Commands { diff --git a/OrbitalShell-Kernel-Commands/OrbitalShell-Kernel-Commands.csproj b/OrbitalShell-Kernel-Commands/OrbitalShell-Kernel-Commands.csproj index f4848632..26c7aac7 100644 --- a/OrbitalShell-Kernel-Commands/OrbitalShell-Kernel-Commands.csproj +++ b/OrbitalShell-Kernel-Commands/OrbitalShell-Kernel-Commands.csproj @@ -15,8 +15,8 @@ Orbital Shell - Kernel commands module Orbital Shell kernel commands module. Orbital Shell is a command shell based inspired by bash and POSIX recommendations, coded in C# .Net Core (c) Orbital Shell 2020 - 1.0.8 - 1.0.8 + 1.0.9 + 1.0.9 milestone 1 MIT @@ -50,6 +50,7 @@ true false bin/Debug/net5.0/OrbitalShell-Kernel-Commands.xml + 1701;1702;1591;1572;1573 diff --git a/OrbitalShell-Kernel/Component/CommandLine/Processor/CommandEvaluationContext.cs b/OrbitalShell-Kernel/Component/CommandLine/Processor/CommandEvaluationContext.cs index 374a1344..12ba2287 100644 --- a/OrbitalShell-Kernel/Component/CommandLine/Processor/CommandEvaluationContext.cs +++ b/OrbitalShell-Kernel/Component/CommandLine/Processor/CommandEvaluationContext.cs @@ -88,7 +88,7 @@ public CommandEvaluationContext( CommandLineProcessor = commandLineProcessor; SetStreams(@out, @in, err); InputData = inputData; - + SetupShellEnvVar(); Variables = new Variables((VariableNamespace.env, ShellEnv)); ShellEnv.Initialize(this); diff --git a/OrbitalShell-Kernel/Component/CommandLine/Processor/CommandLineProcessor.cs b/OrbitalShell-Kernel/Component/CommandLine/Processor/CommandLineProcessor.cs index b8efb20f..2fde045c 100644 --- a/OrbitalShell-Kernel/Component/CommandLine/Processor/CommandLineProcessor.cs +++ b/OrbitalShell-Kernel/Component/CommandLine/Processor/CommandLineProcessor.cs @@ -24,6 +24,7 @@ using System.Text; using OrbitalShell.Lib.Process; using OrbitalShell.Component.Console; +using OrbitalShell.Component.Shell.Hook; namespace OrbitalShell.Component.CommandLine.Processor { @@ -72,6 +73,8 @@ public ICommandLineProcessorSettings Settings public IModuleManager ModuleManager { get; protected set; } + public IHookManager HookManager { get; protected set; } + public IConsole Console { get; protected set; } string[] _args; @@ -143,12 +146,12 @@ void SetVariable(CommandEvaluationContext context, string name, string value) #region command engine operations public CommandLineProcessor( - //IServiceProviderScope scope, IConsole console, ICommandBatchProcessor cbp, ICommandsAlias cal, ISyntaxAnalyser sa, IModuleManager modManager, + IHookManager hookManager, IExternalParserExtension parserExt, ICommandLineProcessorSettings settings = null ) @@ -162,8 +165,8 @@ public CommandLineProcessor( parserExt.CommandLineProcessor = this; SyntaxAnalyzer = sa; ModuleManager = modManager; + HookManager = hookManager; _settings = settings; - //_settings = settings ?? scope.ServiceProvider.GetRequiredService(); CommandBatchProcessor = cbp; CommandsAlias = cal; } diff --git a/OrbitalShell-Kernel/Component/CommandLine/Processor/ICommandLineProcessor.cs b/OrbitalShell-Kernel/Component/CommandLine/Processor/ICommandLineProcessor.cs index e18f9c86..09bbece6 100644 --- a/OrbitalShell-Kernel/Component/CommandLine/Processor/ICommandLineProcessor.cs +++ b/OrbitalShell-Kernel/Component/CommandLine/Processor/ICommandLineProcessor.cs @@ -7,6 +7,7 @@ using OrbitalShell.Component.CommandLine.Reader; using OrbitalShell.Component.Console; using OrbitalShell.Component.Shell; +using OrbitalShell.Component.Shell.Hook; using OrbitalShell.Component.Shell.Module; namespace OrbitalShell.Component.CommandLine.Processor @@ -25,6 +26,7 @@ public interface ICommandLineProcessor bool IsCancellationRequested { get; } bool IsInitialized { get; set; } IModuleManager ModuleManager { get; } + ICommandLineProcessorSettings Settings { get; } ISyntaxAnalyser SyntaxAnalyzer { get; } diff --git a/OrbitalShell-Kernel/Component/CommandLine/Reader/CommandLineReader.cs b/OrbitalShell-Kernel/Component/CommandLine/Reader/CommandLineReader.cs index b5da548e..2de3d8d2 100644 --- a/OrbitalShell-Kernel/Component/CommandLine/Reader/CommandLineReader.cs +++ b/OrbitalShell-Kernel/Component/CommandLine/Reader/CommandLineReader.cs @@ -400,9 +400,7 @@ public int BeginReadln( switch (c.Key) { - /// - /// CR: default end of input - /// + // CR: default end of input case ConsoleKey.Enter: context.CommandLineProcessor.ModuleManager.ModuleHookManager @@ -411,9 +409,7 @@ public int BeginReadln( break; - /// - /// ESC : clean-up input and set cursor at begin of line (after prompt) - /// + // ESC : clean-up input and set cursor at begin of line (after prompt) case ConsoleKey.Escape: context.CommandLineProcessor.ModuleManager.ModuleHookManager @@ -424,9 +420,7 @@ public int BeginReadln( break; - /// - /// HOME : set cursor position at begin of input (just after prompt) - /// + // HOME : set cursor position at begin of input (just after prompt) case ConsoleKey.Home: context.CommandLineProcessor.ModuleManager.ModuleHookManager @@ -439,9 +433,7 @@ public int BeginReadln( } break; - /// - /// END : set cursor position at end of input - /// + // END : set cursor position at end of input case ConsoleKey.End: context.CommandLineProcessor.ModuleManager.ModuleHookManager diff --git a/OrbitalShell-Kernel/Component/Shell/Hook/HookManager.cs b/OrbitalShell-Kernel/Component/Shell/Hook/HookManager.cs index c4e28129..7b504222 100644 --- a/OrbitalShell-Kernel/Component/Shell/Hook/HookManager.cs +++ b/OrbitalShell-Kernel/Component/Shell/Hook/HookManager.cs @@ -69,7 +69,7 @@ public AggregateHookResult InvokeHooks( Action callBack = null ) { - if (context.ShellEnv.IsOptionSetted(ShellEnvironmentVar.debug_enableHookTrace)) + if (context.ShellEnv.IsOptionSetted(ShellEnvironmentVar.debug_enableHookTrace,false)) context.Out.Echo(context.ShellEnv.Colors.Log + "[invoke hook: " + name + "](rdc) "); AggregateHookResult result = null; diff --git a/OrbitalShell-Kernel/Component/Shell/IShellStartup.cs b/OrbitalShell-Kernel/Component/Shell/IShellStartup.cs new file mode 100644 index 00000000..1270d6dc --- /dev/null +++ b/OrbitalShell-Kernel/Component/Shell/IShellStartup.cs @@ -0,0 +1,7 @@ +namespace OrbitalShell.Component.Shell +{ + public interface IShellStartup + { + int Startup(string[] args); + } +} \ No newline at end of file diff --git a/OrbitalShell-Kernel/Component/Shell/Variable/ShellEnvironment.cs b/OrbitalShell-Kernel/Component/Shell/Variable/ShellEnvironment.cs index 66cdcefc..4ded16e1 100644 --- a/OrbitalShell-Kernel/Component/Shell/Variable/ShellEnvironment.cs +++ b/OrbitalShell-Kernel/Component/Shell/Variable/ShellEnvironment.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Data; using OrbitalShell.Component.Shell.Module.Data; +using OrbitalShell.Component.Shell.Hook; namespace OrbitalShell.Component.Shell.Variable { @@ -41,9 +42,11 @@ public ShellEnvironment(string name) : base(name, false) { } /// /// public void Initialize(CommandEvaluationContext context) - { + { Vars = context.Variables; + context.CommandLineProcessor.HookManager.InvokeHooks(context, Hooks.ShellStartsInitializing); + // data objects foreach (var shellNs in Enum.GetValues(typeof(ShellEnvironmentNamespace))) @@ -392,7 +395,6 @@ public DataValue SetValue(string varPath, string varName, object value) return o; } - #region getters public bool Get(ShellEnvironmentVar var, out object value, bool throwException = true) @@ -406,15 +408,29 @@ public DataValue GetDataValue(ShellEnvironmentVar var, bool throwException = tru var path = Nsp(var); return Vars.GetValue(path, throwException); } + public DataValue GetDataValue(string path, bool throwException = true) { return Vars.GetValue(path, throwException); } - public T GetValue(ShellEnvironmentVar var, bool throwException = true) => (T)GetDataValue(var, throwException).Value; - public T GetValue(string varPath, string varName, bool throwException = true) => (T)GetDataValue(Nsp(varPath, varName), throwException).Value; - public bool IsOptionSetted(ShellEnvironmentVar @var) => GetValue(@var, false); - public bool IsOptionSetted(string Namespace, string varName) => Vars.GetValue(Nsp(Namespace, varName)); + public T GetValue(ShellEnvironmentVar var, bool throwException = true) + { + var v = GetDataValue(var, throwException); + if (v.Value == null) return default; + var tv = (T)(v.Value); + return tv; + } + + public T GetValue(string varPath, string varName, bool throwException = true) { + var v = GetDataValue(Nsp(varPath, varName), throwException); + if (v.Value == null) return default; + var tv = (T)(v.Value); + return tv; + } + + public bool IsOptionSetted(ShellEnvironmentVar @var, bool throwException = true) => GetValue(@var, throwException); + public bool IsOptionSetted(string Namespace, string varName, bool throwException = true) => Vars.GetValue(Nsp(Namespace, varName), throwException); #endregion diff --git a/OrbitalShell-Kernel/Component/Shell/Variable/Variables.cs b/OrbitalShell-Kernel/Component/Shell/Variable/Variables.cs index 5fff0df3..b1069a93 100644 --- a/OrbitalShell-Kernel/Component/Shell/Variable/Variables.cs +++ b/OrbitalShell-Kernel/Component/Shell/Variable/Variables.cs @@ -140,9 +140,9 @@ public bool Get(string rootPath, string path, out object value, bool throwExcept public bool Get(VariableNamespace rootPath, string path, out object value, bool throwException = true) => Get(Nsp(rootPath, path), out value, throwException); - public T GetValue(string path) => (T)GetValue(path).Value; - public T GetValue(string rootPath, string path) => (T)GetValue(Nsp(rootPath, path)).Value; - public T GetValue(VariableNamespace rootPath, string path) => (T)GetValue(Nsp(rootPath, path)).Value; + public T GetValue(string path, bool throwException = true) => (T)GetValue(path,throwException).Value; + public T GetValue(string rootPath, string path, bool throwException = true) => (T)GetValue(Nsp(rootPath, path), throwException).Value; + public T GetValue(VariableNamespace rootPath, string path, bool throwException = true) => (T)GetValue(Nsp(rootPath, path), throwException).Value; public bool GetDataObject(string path, out IDataObject value, bool throwException = true) { @@ -181,7 +181,8 @@ public DataValue GetValue(string path, bool throwException = true) return (DataValue)data; if (throwException) throw new VariablePathNotFoundException(path); - return null; + // a real null DataValue + return new DataValue(path,null,false); } public DataValue GetValue(string rootPath, string path, bool throwException = true) => GetValue(Nsp(rootPath, path), throwException); diff --git a/OrbitalShell-Kernel/ModuleInfo.cs b/OrbitalShell-Kernel/ModuleInfo.cs index ee9819cb..7df6f29c 100644 --- a/OrbitalShell-Kernel/ModuleInfo.cs +++ b/OrbitalShell-Kernel/ModuleInfo.cs @@ -1,12 +1,11 @@ using OrbitalShell.Component.Shell.Module; using OrbitalShell.Lib; -/// -/// declare a shell module -/// +// declare a shell module + [assembly: ShellModule("OrbitalShell-Kernel")] [assembly: ModuleTargetPlateform(TargetPlatform.Any)] -[assembly: ModuleShellMinVersion("1.0.8")] +[assembly: ModuleShellMinVersion("1.0.9")] [assembly: ModuleAuthors("Orbital Shell team")] namespace OrbitalShell.Kernel { diff --git a/OrbitalShell-Kernel/OrbitalShell-Kernel.csproj b/OrbitalShell-Kernel/OrbitalShell-Kernel.csproj index b01ab58b..4b99148e 100644 --- a/OrbitalShell-Kernel/OrbitalShell-Kernel.csproj +++ b/OrbitalShell-Kernel/OrbitalShell-Kernel.csproj @@ -14,8 +14,8 @@ Orbital Shell - Kernel Orbital Shell kernel - Orbital Shell is a command shell based inspired by bash and POSIX recommendations, coded in C# .Net Core (c) 2020 Licence MIT - 1.0.8 - 1.0.8 + 1.0.9 + 1.0.9 milestone 1 MIT @@ -50,6 +50,7 @@ false TRACE;DBG_DI_INSTANCE_disabled bin/Debug/net5.0/OrbitalShell-Kernel.xml + 1701;1702;1591;1572;1573