Skip to content

Commit

Permalink
fix module package id retreive/store/register (step 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
franck-gaspoz committed Feb 22, 2021
1 parent c6b82fa commit 28c0878
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 26 deletions.
4 changes: 2 additions & 2 deletions OrbitalShell-CLI/OrbitalShell-CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<Product>Orbital Shell</Product>
<Description>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.</Description>
<Copyright>(c) 2020 Licence MIT</Copyright>
<Version>1.0.5</Version>
<InformationalVersion>1.0.5</InformationalVersion>
<Version>1.0.6</Version>
<InformationalVersion>1.0.6</InformationalVersion>

<PackageReleaseNotes>initial stable release (milestone 1)</PackageReleaseNotes>
<ApplicationIcon>assets\robotazteque.ico</ApplicationIcon>
Expand Down
2 changes: 1 addition & 1 deletion OrbitalShell-CLI/Scripts/publish-binaries.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!porbsh
# build/publish orbital shell binaries

set version 1.0.5
set version 1.0.6
set nugetext .nupkg

cls
Expand Down
4 changes: 2 additions & 2 deletions OrbitalShell-ConsoleApp/OrbitalShell-ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<Product>Orbital Shell - ConsoleApp</Product>
<Description>Orbital Shell console application library</Description>
<Copyright>(c) 2020 Licence MIT</Copyright>
<Version>1.0.5</Version>
<InformationalVersion>1.0.5</InformationalVersion>
<Version>1.0.6</Version>
<InformationalVersion>1.0.6</InformationalVersion>

<PackageReleaseNotes>milestone 1</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
51 changes: 39 additions & 12 deletions OrbitalShell-Kernel-Commands/Commands/Shell/ShellCommands_Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ public CommandResult<List<ModuleSpecification>> 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)
{
// 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<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
Expand Down Expand Up @@ -92,22 +93,46 @@ public CommandResult<List<ModuleSpecification>> 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<List<ModuleSpecification>>(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);
Expand All @@ -133,12 +158,13 @@ public CommandResult<List<ModuleSpecification>> 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");
Expand All @@ -150,7 +176,7 @@ public CommandResult<List<ModuleSpecification>> 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;
Expand Down Expand Up @@ -179,7 +205,7 @@ public CommandResult<List<ModuleSpecification>> 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... ");
Expand Down Expand Up @@ -265,17 +291,18 @@ public CommandResult<List<ModuleSpecification>> 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
Expand Down
4 changes: 2 additions & 2 deletions OrbitalShell-Kernel-Commands/ModuleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/// <summary>
/// declare a shell module
/// </summary>
[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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<Product>Orbital Shell - Kernel commands module</Product>
<Description>Orbital Shell kernel commands module. Orbital Shell is a command shell based inspired by bash and POSIX recommendations, coded in C# .Net Core</Description>
<Copyright>(c) Orbital Shell 2020</Copyright>
<Version>1.0.2</Version>
<InformationalVersion>1.0.2</InformationalVersion>
<Version>1.0.6</Version>
<InformationalVersion>1.0.6</InformationalVersion>

<PackageReleaseNotes>milestone 1</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace OrbitalShell.Component.Shell.Module
[AttributeUsage(AttributeTargets.Assembly)]
public class ShellModuleAttribute : Attribute
{
public ShellModuleAttribute() { }
public readonly string PackageId;

/// <summary>
/// declare the assembly beeing a shell module having the specified package ID (must match PackageID in .csproj)
/// </summary>
/// <param name="packageId"></param>
public ShellModuleAttribute(string packageId) { PackageId = packageId; }
}
}
4 changes: 2 additions & 2 deletions OrbitalShell-Kernel/ModuleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/// <summary>
/// declare a shell module
/// </summary>
[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
{
Expand Down
4 changes: 2 additions & 2 deletions OrbitalShell-Kernel/OrbitalShell-Kernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<Product>Orbital Shell - Kernel</Product>
<Description>Orbital Shell kernel - Orbital Shell is a command shell based inspired by bash and POSIX recommendations, coded in C# .Net Core</Description>
<Copyright>(c) 2020 Licence MIT</Copyright>
<Version>1.0.2</Version>
<InformationalVersion>1.0.2</InformationalVersion>
<Version>1.0.6</Version>
<InformationalVersion>1.0.6</InformationalVersion>

<PackageReleaseNotes>milestone 1</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down

0 comments on commit 28c0878

Please sign in to comment.