From 28c0878538cb650f66579d4528328b3f682dad64 Mon Sep 17 00:00:00 2001 From: franck gaspoz Date: Mon, 22 Feb 2021 03:10:21 +0100 Subject: [PATCH] fix module package id retreive/store/register (step 1) --- OrbitalShell-CLI/OrbitalShell-CLI.csproj | 4 +- OrbitalShell-CLI/Scripts/publish-binaries.sh | 2 +- .../OrbitalShell-ConsoleApp.csproj | 4 +- .../Commands/Shell/ShellCommands_Mod.cs | 51 ++++++++++++++----- OrbitalShell-Kernel-Commands/ModuleInfo.cs | 4 +- .../OrbitalShell-Kernel-Commands.csproj | 4 +- .../Shell/Module/ShellModuleAttribute.cs | 8 ++- OrbitalShell-Kernel/ModuleInfo.cs | 4 +- .../OrbitalShell-Kernel.csproj | 4 +- 9 files changed, 59 insertions(+), 26 deletions(-) diff --git a/OrbitalShell-CLI/OrbitalShell-CLI.csproj b/OrbitalShell-CLI/OrbitalShell-CLI.csproj index caa7ddd3..afd94f62 100644 --- a/OrbitalShell-CLI/OrbitalShell-CLI.csproj +++ b/OrbitalShell-CLI/OrbitalShell-CLI.csproj @@ -18,8 +18,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.5 - 1.0.5 + 1.0.6 + 1.0.6 initial stable release (milestone 1) assets\robotazteque.ico diff --git a/OrbitalShell-CLI/Scripts/publish-binaries.sh b/OrbitalShell-CLI/Scripts/publish-binaries.sh index 4c0bf79c..1b793782 100644 --- a/OrbitalShell-CLI/Scripts/publish-binaries.sh +++ b/OrbitalShell-CLI/Scripts/publish-binaries.sh @@ -1,7 +1,7 @@ #!porbsh # build/publish orbital shell binaries -set version 1.0.5 +set version 1.0.6 set nugetext .nupkg cls diff --git a/OrbitalShell-ConsoleApp/OrbitalShell-ConsoleApp.csproj b/OrbitalShell-ConsoleApp/OrbitalShell-ConsoleApp.csproj index b3afa942..f83c2bc8 100644 --- a/OrbitalShell-ConsoleApp/OrbitalShell-ConsoleApp.csproj +++ b/OrbitalShell-ConsoleApp/OrbitalShell-ConsoleApp.csproj @@ -15,8 +15,8 @@ Orbital Shell - ConsoleApp Orbital Shell console application library (c) 2020 Licence MIT - 1.0.5 - 1.0.5 + 1.0.6 + 1.0.6 milestone 1 MIT diff --git a/OrbitalShell-Kernel-Commands/Commands/Shell/ShellCommands_Mod.cs b/OrbitalShell-Kernel-Commands/Commands/Shell/ShellCommands_Mod.cs index fac15903..6588dc11 100644 --- a/OrbitalShell-Kernel-Commands/Commands/Shell/ShellCommands_Mod.cs +++ b/OrbitalShell-Kernel-Commands/Commands/Shell/ShellCommands_Mod.cs @@ -51,6 +51,7 @@ public CommandResult> Module( bool fetchInfo = fetchInfoName != null; var clog = context.ShellEnv.Colors.Log; var o = context.Out; + string n; if (loadModulePath == null && unloadModuleName == null && updateModuleName == null && installModuleName == null && uninstallModuleName == null && !fetchList && !fetchInfo) @@ -58,7 +59,7 @@ public CommandResult> Module( // output reports on loaded modules var col1length = context.CommandLineProcessor.ModuleManager.Modules.Values.Select(x => x.Name.Length).Max() + 1; - int n = 1; + int i = 1; foreach (var kvp in context.CommandLineProcessor.ModuleManager.Modules) { var ver = kvp.Value.Assembly.GetCustomAttribute()?.InformationalVersion; @@ -92,22 +93,46 @@ public CommandResult> Module( { o.Echoln($"{"".PadRight(col1length, ' ')}{context.ShellEnv.Colors.Label}version : {context.ShellEnv.Colors.HalfDark}{ver} (target {((target == null) ? "" : target + ", ")}created {dat}) {context.ShellEnv.Colors.Label}Company : (rdc){comp} ({aut}) "); } - if (n < context.CommandLineProcessor.ModuleManager.Modules.Count) o.Echoln(); - n++; + if (i < context.CommandLineProcessor.ModuleManager.Modules.Count) o.Echoln(); + i++; } return new CommandResult>(context.CommandLineProcessor.ModuleManager.Modules.Values.ToList()); } if (!fetchList && !fetchInfo) { + // update module name + + if (updateModuleName!=null) + { + n = updateModuleName; + if (ModuleUtil.IsModuleInstalled(context, n)) + { + var modSpec = context.CommandLineProcessor.ModuleManager.GetModule(context, n); + if (modSpec == null) + return _ModuleErr(context, $"module specification not found for module name '{n}'"); + + var getVersMethod = typeof(NuGetServerApiCommands).GetMethod("NugetVer"); + var r = context.CommandLineProcessor.Eval(context, getVersMethod, $"{n}", 0); + if (r.EvalResultCode == (int)ReturnCode.OK) + { + var vers = (PackageVersions)r.Result; + } + else + return _ModuleErr(context, $"module id '{n}' not found at NuGet"); + } else + return _ModuleErr(context, $"module '{n}' is not installed"); + } + // uninstall module if (uninstallModuleName!=null) { - var folderName = uninstallModuleName.ToLower(); + n = uninstallModuleName; + var folderName = n.ToLower(); if (!ModuleUtil.IsModuleInstalled( context, folderName )) // error not installed - return _ModuleErr(context, $"module '{uninstallModuleName}' is not installed"); + return _ModuleErr(context, $"module '{n}' is not installed"); o.Echoln(clog + "removing potentially registered dlls:"); var modInit = ModuleUtil.LoadModuleInitConfiguration(context); @@ -133,12 +158,13 @@ public CommandResult> Module( if (installModuleName != null) { + n = installModuleName; var lastVer = string.IsNullOrWhiteSpace(version); #region fetch module info var queryMethod = typeof(NuGetServerApiCommands).GetMethod("NugetQuery"); - var r0 = context.CommandLineProcessor.Eval(context, queryMethod, $"{installModuleName} -t 1",0); + var r0 = context.CommandLineProcessor.Eval(context, queryMethod, $"{n} -t 1",0); if (r0.EvalResultCode!=(int)ReturnCode.OK) return _ModuleErr(context, r0.ErrorReason); var queryRes = r0.Result as QueryResultRoot; if (queryRes==null) return _ModuleErr(context, "nuget query return a null result"); @@ -150,7 +176,7 @@ public CommandResult> Module( o.Echoln(); var getVersMethod = typeof(NuGetServerApiCommands).GetMethod("NugetVer"); - var r = context.CommandLineProcessor.Eval(context, getVersMethod, $"{installModuleName}", 0); + var r = context.CommandLineProcessor.Eval(context, getVersMethod, $"{n}", 0); if (r.EvalResultCode==(int)ReturnCode.OK) { var vers = (PackageVersions)r.Result; @@ -179,7 +205,7 @@ public CommandResult> Module( if (!Directory.Exists(moduleFolder)) Directory.CreateDirectory(moduleFolder); moduleFolder = FileSystemPath.UnescapePathSeparators(moduleFolder); - var rd = context.CommandLineProcessor.Eval(context, dwnMethod, $"{installModuleName} {version} -o {moduleFolder}", 0); + var rd = context.CommandLineProcessor.Eval(context, dwnMethod, $"{n} {version} -o {moduleFolder}", 0); if (rd.EvalResultCode==(int)ReturnCode.OK) { o.Echo(clog + "extracting package... "); @@ -265,17 +291,18 @@ public CommandResult> Module( return _ModuleErr(null,null); } - // unload module + // unload module (unregistered in session) if (unloadModuleName != null) { - if (context.CommandLineProcessor.ModuleManager.Modules.Values.Any(x => x.Name == unloadModuleName)) + n = unloadModuleName; + if (context.CommandLineProcessor.ModuleManager.Modules.Values.Any(x => x.Name == n)) { - moduleSpecification = context.CommandLineProcessor.ModuleManager.UnregisterModule(context, unloadModuleName); + moduleSpecification = context.CommandLineProcessor.ModuleManager.UnregisterModule(context, n); if (moduleSpecification != null && moduleSpecification.Info != null) o.Echoln($"unloaded: {moduleSpecification.Info.GetDescriptor(context)}"); } else - return _ModuleErr(context, $"module '{unloadModuleName}' is not registered"); + return _ModuleErr(context, $"module '{n}' is not registered"); } } else diff --git a/OrbitalShell-Kernel-Commands/ModuleInfo.cs b/OrbitalShell-Kernel-Commands/ModuleInfo.cs index 1867bf8f..c9e551d1 100644 --- a/OrbitalShell-Kernel-Commands/ModuleInfo.cs +++ b/OrbitalShell-Kernel-Commands/ModuleInfo.cs @@ -4,9 +4,9 @@ /// /// declare a shell module /// -[assembly: ShellModule()] +[assembly: ShellModule("OrbitalShell-Kernel-Commands")] [assembly: ModuleTargetPlateform(TargetPlatform.Any)] -[assembly: ModuleShellMinVersion("1.0.1-beta4")] +[assembly: ModuleShellMinVersion("1.0.6")] [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 0c9f1542..564c0c20 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.2 - 1.0.2 + 1.0.6 + 1.0.6 milestone 1 MIT diff --git a/OrbitalShell-Kernel/Component/Shell/Module/ShellModuleAttribute.cs b/OrbitalShell-Kernel/Component/Shell/Module/ShellModuleAttribute.cs index e1aff392..698c0a0d 100644 --- a/OrbitalShell-Kernel/Component/Shell/Module/ShellModuleAttribute.cs +++ b/OrbitalShell-Kernel/Component/Shell/Module/ShellModuleAttribute.cs @@ -8,6 +8,12 @@ namespace OrbitalShell.Component.Shell.Module [AttributeUsage(AttributeTargets.Assembly)] public class ShellModuleAttribute : Attribute { - public ShellModuleAttribute() { } + public readonly string PackageId; + + /// + /// declare the assembly beeing a shell module having the specified package ID (must match PackageID in .csproj) + /// + /// + public ShellModuleAttribute(string packageId) { PackageId = packageId; } } } diff --git a/OrbitalShell-Kernel/ModuleInfo.cs b/OrbitalShell-Kernel/ModuleInfo.cs index 03505dc2..f63b0d7d 100644 --- a/OrbitalShell-Kernel/ModuleInfo.cs +++ b/OrbitalShell-Kernel/ModuleInfo.cs @@ -4,9 +4,9 @@ /// /// declare a shell module /// -[assembly: ShellModule()] +[assembly: ShellModule("OrbitalShell-Kernel")] [assembly: ModuleTargetPlateform(TargetPlatform.Any)] -[assembly: ModuleShellMinVersion("1.0.1-beta4")] +[assembly: ModuleShellMinVersion("1.0.6")] [assembly: ModuleAuthors("Orbital Shell team")] namespace OrbitalShell.Kernel { diff --git a/OrbitalShell-Kernel/OrbitalShell-Kernel.csproj b/OrbitalShell-Kernel/OrbitalShell-Kernel.csproj index 431de5b2..c471e202 100644 --- a/OrbitalShell-Kernel/OrbitalShell-Kernel.csproj +++ b/OrbitalShell-Kernel/OrbitalShell-Kernel.csproj @@ -15,8 +15,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.2 - 1.0.2 + 1.0.6 + 1.0.6 milestone 1 MIT