Skip to content

Commit 841c97f

Browse files
committed
List available plugins
1 parent 91c9c8f commit 841c97f

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

src/InEngine.Core/InEngine.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<Compile Include="Queue\AbstractBrokerCommand.cs" />
9090
<Compile Include="IOptions.cs" />
9191
<Compile Include="Queue\Options.cs" />
92+
<Compile Include="Plugin.cs" />
9293
</ItemGroup>
9394
<ItemGroup>
9495
<None Include="packages.config" />

src/InEngine.Core/Plugin.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Reflection;
3+
4+
namespace InEngine.Core
5+
{
6+
public class Plugin
7+
{
8+
public Assembly Assembly { get; set; }
9+
public string Name { get { return Assembly.GetName().Name; } }
10+
11+
public Plugin(Assembly assembly)
12+
{
13+
Assembly = assembly;
14+
}
15+
}
16+
}

src/InEngine.Net.userprefs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<Properties StartupConfiguration="{DF1A45FD-4887-4D65-8BAD-EE17B70FE79D}|Default">
22
<MonoDevelop.Ide.ItemProperties.InEngineScheduler PreferredExecutionTarget="MonoDevelop.Default" />
3-
<MonoDevelop.Ide.Workbench ActiveDocument="InEngine.Commands/Options.cs">
3+
<MonoDevelop.Ide.Workbench ActiveDocument="InEngineCli/ArgumentInterpreter.cs">
44
<Files>
5-
<File FileName="InEngineCli/ArgumentInterpreter.cs" Line="61" Column="1" />
6-
<File FileName="InEngine.Commands/Options.cs" Line="16" Column="30" />
5+
<File FileName="InEngineCli/ArgumentInterpreter.cs" Line="25" Column="1" />
6+
<File FileName="InEngine.Commands/Options.cs" Line="19" Column="25" />
7+
<File FileName="InEngineCli/Options.cs" Line="20" Column="1" />
8+
<File FileName="InEngine.Core/Plugin.cs" Line="17" Column="1" />
79
</Files>
810
<Pads>
911
<Pad Id="ProjectPad">
1012
<State name="__root__">
1113
<Node name="InEngine.Net" expanded="True">
12-
<Node name="InEngine.Commands" expanded="True">
13-
<Node name="Options.cs" selected="True" />
14+
<Node name="InEngine.Commands" expanded="True" />
15+
<Node name="InEngine.Core" expanded="True" />
16+
<Node name="InEngineCli" expanded="True">
17+
<Node name="ArgumentInterpreter.cs" selected="True" />
1418
</Node>
15-
<Node name="InEngine.Core" expanded="True">
16-
<Node name="Queue" expanded="True" />
17-
</Node>
18-
<Node name="InEngineCli" expanded="True" />
1919
<Node name="InEngineScheduler" expanded="True" />
2020
</Node>
2121
</State>
@@ -26,8 +26,6 @@
2626
<MonoDevelop.Ide.DebuggingService.Breakpoints>
2727
<BreakpointStore>
2828
<Breakpoint file="/Users/hanne01/InEngine.NET/src/InEngine.Commands/CommandOptions.cs" relfile="InEngine.Commands/CommandOptions.cs" line="8" column="1" />
29-
<Breakpoint file="/Users/hanne01/InEngine.NET/src/InEngineCli/ArgumentInterpreter.cs" relfile="InEngineCli/ArgumentInterpreter.cs" line="61" column="1" />
30-
<Breakpoint file="/Users/hanne01/InEngine.NET/src/InEngineCli/ArgumentInterpreter.cs" relfile="InEngineCli/ArgumentInterpreter.cs" line="53" column="1" />
3129
</BreakpointStore>
3230
</MonoDevelop.Ide.DebuggingService.Breakpoints>
3331
<MonoDevelop.Ide.DebuggingService.PinnedWatches />

src/InEngineCli/ArgumentInterpreter.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
24
using System.Linq;
35
using System.Reflection;
46
using InEngine.Core;
@@ -18,6 +20,13 @@ public ArgumentInterpreter()
1820

1921
public void Interpret(string[] args)
2022
{
23+
if (!args.Any())
24+
{
25+
Console.WriteLine("Available plugins... ");
26+
FindPlugins().ForEach(x => Console.WriteLine(x.Name));
27+
ExitWithSuccess();
28+
}
29+
2130
var parser = new CommandLine.Parser(with => with.IgnoreUnknownArguments = true);
2231
var options = new Options();
2332

@@ -26,6 +35,9 @@ public void Interpret(string[] args)
2635
if (options == null)
2736
Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
2837

38+
// Get plugins.
39+
// If no arg is specified, list plugins
40+
2941
// Get possible types from plugin assembly.
3042
var targetAssembly = Assembly.LoadFrom(options.PlugInName + ".dll");
3143
var types = targetAssembly.GetTypes();
@@ -62,6 +74,16 @@ public void ExitWithFailure(Exception exception = null)
6274
Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
6375
}
6476

77+
public List<Plugin> FindPlugins()
78+
{
79+
return Directory
80+
.GetFiles(".", "*.dll")
81+
.Select(x => Assembly.LoadFrom(x))
82+
.Where(x => x.GetTypes().Any(y => y.IsClass && typeof(IOptions).IsAssignableFrom(y)))
83+
.Select(x => new Plugin(x))
84+
.ToList();
85+
}
86+
6587
public void InterpretPluginArguments(string[] pluginArgs, IOptions pluginOptions)
6688
{
6789
var isSuccessful = CommandLine

0 commit comments

Comments
 (0)