Skip to content

Commit 738c89a

Browse files
committed
Remove need for specifying plugin name
1 parent cbf744f commit 738c89a

File tree

6 files changed

+38
-31
lines changed

6 files changed

+38
-31
lines changed

src/InEngine.Core/AbstractCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Linq;
33
using System.Threading.Tasks;
4+
using CommandLine;
5+
using CommandLine.Text;
46
using InEngine.Core.Exceptions;
57
using InEngine.Core.IO;
68
using InEngine.Core.LifeCycle;

src/InEngine.Core/AbstractPlugin.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ public virtual void Schedule(ISchedule schedule)
1111
{}
1212

1313
[HelpVerbOption]
14-
public virtual string GetUsage(string verb)
14+
public string GetUsage(string verb)
1515
{
16-
return HelpText.AutoBuild(this, verb);
16+
var helpText = HelpText.AutoBuild(this, verb);
17+
helpText.Heading = $"{GetType().Assembly.GetName().Name} v{GetType().Assembly.GetName().Version.ToString()}";
18+
return helpText;
19+
}
20+
21+
public virtual string GetUsageWithoutHeader()
22+
{
23+
var helpText = new HelpText();
24+
helpText.AddOptions(this);
25+
return helpText;
1726
}
1827
}
1928
}

src/InEngine.Core/PluginAssembly.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ public class PluginAssembly
1313
public Assembly Assembly { get; set; }
1414
public string Name { get { return Assembly.GetName().Name; } }
1515
public string Version { get { return Assembly.GetName().Version.ToString(); } }
16-
16+
public List<AbstractPlugin> Plugins { get; set; }
1717
public PluginAssembly(Assembly assembly)
1818
{
1919
Assembly = assembly;
20+
Plugins = Make<AbstractPlugin>();
2021
}
2122

2223
public static PluginAssembly LoadFrom(string assemblyPath)

src/InEngine.Core/Queuing/QueuingPlugin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using CommandLine;
4+
using CommandLine.Text;
45
using InEngine.Core.Queuing.Commands;
56
using InEngine.Core.Scheduling;
67

src/InEngine/ArgumentInterpreter.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,24 @@ public void Interpret(string[] args)
5555
ExitWithSuccess();
5656
}
5757

58+
var pluginArgs = args.ToArray();
59+
var firstPluginArg = pluginArgs.FirstOrDefault();
60+
var firstArgIsConf = firstPluginArg.StartsWith("-c", StringComparison.OrdinalIgnoreCase) ||
61+
firstPluginArg.StartsWith("--configuration", StringComparison.OrdinalIgnoreCase);
5862

59-
var plugin = pluginAssemblies.FirstOrDefault(x => x.Name == options.PluginName);
60-
61-
if (plugin == null)
62-
ExitWithFailure("Plugin does not exist: " + options.PluginName);
63-
64-
var pluginOptionList = plugin.Make<AbstractPlugin>();
63+
if (firstArgIsConf)
64+
pluginArgs = pluginArgs.Skip(1).ToArray();
6565

66-
var pluginArgs = args.Skip(1).ToArray();
66+
var commandVerbName = pluginArgs.FirstOrDefault();
6767

68-
if (!pluginArgs.ToList().Any()) {
69-
PrintPluginHelpTextAndExit(plugin, pluginOptionList, pluginArgs);
70-
}
68+
foreach(var assembly in pluginAssemblies)
69+
foreach (var ops in assembly.Plugins)
70+
foreach (var prop in ops.GetType().GetProperties())
71+
foreach (object attr in prop.GetCustomAttributes(true))
72+
if (attr is VerbOptionAttribute commandVerb && (commandVerb.LongName == commandVerbName || commandVerb.ShortName.ToString() == commandVerbName))
73+
InterpretPluginArguments(pluginArgs, ops);
7174

72-
if (new[] { "-p", "--plugin-name", "-c", "--configuration" }.Any(c => pluginArgs.First().StartsWith("-p", StringComparison.OrdinalIgnoreCase)))
73-
pluginArgs = pluginArgs.Skip(1).ToArray();
74-
75-
// Need to remove plugin options
76-
var commandVerbName = pluginArgs.First();
77-
foreach (var ops in pluginOptionList)
78-
foreach (var prop in ops.GetType().GetProperties())
79-
foreach (object attr in prop.GetCustomAttributes(true))
80-
if (attr is VerbOptionAttribute commandVerb && (commandVerb.LongName == commandVerbName || commandVerb.ShortName.ToString() == commandVerbName))
81-
InterpretPluginArguments(pluginArgs, ops);
75+
PrintInEngineHelpTextAndExit(pluginAssemblies, options);
8276
}
8377
}
8478

@@ -169,11 +163,14 @@ public void PrintInEngineHelpTextAndExit(List<PluginAssembly> plugins, Options o
169163
{
170164
Write.Info(CliLogo);
171165
Write.Text(options.GetUsage(""));
172-
Write.Newline();
173-
Write.Warning("Plugins:");
174-
plugins.ForEach(x => Write.Line($" {x.Name}"));
175-
Write.Newline(2);
176-
ExitWithSuccess();
166+
plugins.ForEach(x => {
167+
Write.Warning(x.Name);
168+
x.Plugins.ForEach(y => {
169+
Write.Line(string.Join(Environment.NewLine, y.GetUsageWithoutHeader().Split('\n').Where(s => !string.IsNullOrWhiteSpace(s))))
170+
.Newline();
171+
});
172+
});
173+
ExitWithSuccess();
177174
}
178175
}
179176
}

src/InEngine/Options.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ namespace InEngine
55
{
66
public class Options
77
{
8-
[Option('p', "plugin", HelpText = "Plug-In to activate.")]
9-
public string PluginName { get; set; }
10-
118
[Option('s', "scheduler", HelpText = "Run the scheduler.")]
129
public bool ShouldRunScheduler { get; set; }
1310

0 commit comments

Comments
 (0)