Skip to content

Commit

Permalink
fix: custom plugins won't shown by command plugins (#3269)
Browse files Browse the repository at this point in the history
* fix: iterate non listed

* fix: Remove null warning

* style: use names

* fix: bug when no plugins

* Update src/Neo.CLI/CLI/MainService.Plugins.cs
  • Loading branch information
shargon authored May 24, 2024
1 parent c8f9338 commit 44c8cd9
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/Neo.CLI/CLI/MainService.Plugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,28 @@ private void OnPluginsCommand()
{
try
{
var plugins = GetPluginListAsync().GetAwaiter().GetResult();
if (plugins == null) return;
plugins
.Order()
.ForEach(f =>
var plugins = GetPluginListAsync().GetAwaiter().GetResult()?.ToArray() ?? [];
var installedPlugins = Plugin.Plugins.ToList();

var maxLength = installedPlugins.Count == 0 ? 0 : installedPlugins.Max(s => s.Name.Length);
if (plugins.Length > 0)
{
var installedPlugin = Plugin.Plugins.SingleOrDefault(pp => string.Equals(pp.Name, f, StringComparison.CurrentCultureIgnoreCase));
if (installedPlugin != null)
maxLength = Math.Max(maxLength, plugins.Max(s => s.Length));
}

plugins.Select(s => (name: s, installedPlugin: Plugin.Plugins.SingleOrDefault(pp => string.Equals(pp.Name, s, StringComparison.InvariantCultureIgnoreCase))))
.Concat(installedPlugins.Select(u => (name: u.Name, installedPlugin: (Plugin?)u)).Where(u => !plugins.Contains(u.name, StringComparer.InvariantCultureIgnoreCase)))
.OrderBy(u => u.name)
.ForEach((f) =>
{
var maxLength = plugins.Select(s => s.Length).OrderDescending().First();
string tabs = string.Empty;
if (f.Length < maxLength)
tabs = "\t";
ConsoleHelper.Info("", $"[Installed]\t {f,6}{tabs}", " @", $"{installedPlugin.Version.ToString(3)} {installedPlugin.Description}");
}
else
ConsoleHelper.Info($"[Not Installed]\t {f}");
});
if (f.installedPlugin != null)
{
var tabs = f.name.Length < maxLength ? "\t" : string.Empty;
ConsoleHelper.Info("", $"[Installed]\t {f.name,6}{tabs}", " @", $"{f.installedPlugin.Version.ToString(3)} {f.installedPlugin.Description}");
}
else
ConsoleHelper.Info($"[Not Installed]\t {f.name}");
});
}
catch (Exception ex)
{
Expand Down

0 comments on commit 44c8cd9

Please sign in to comment.