Skip to content

Commit efe5456

Browse files
committed
Rework Options
1 parent d517891 commit efe5456

File tree

11 files changed

+67
-65
lines changed

11 files changed

+67
-65
lines changed
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
using CommandLine;
2-
using CommandLine.Text;
32
using InEngine.Core;
43

54
namespace InEngine.Commands
65
{
7-
public class Options : IOptions
6+
public class CommandsPlugin : AbstractPlugin
87
{
98
[VerbOption("fail", HelpText = "Always fail. Useful for end-to-end testing.")]
109
public AlwaysFail AlwaysFail { get; set; }
1110

1211
[VerbOption("succeed", HelpText = "A null operation command. Literally does nothing.")]
1312
public AlwaysSucceed Null { get; set; }
14-
15-
[HelpVerbOption]
16-
public string GetUsage(string verb)
17-
{
18-
return HelpText.AutoBuild(this, verb);
19-
}
2013
}
2114
}
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using CommandLine;
2-
using CommandLine.Text;
3-
using InEngine.Commands.Sample;
42
using InEngine.Core;
53

6-
namespace InEngine.Commands
4+
namespace InEngine.Commands.Sample
75
{
8-
public class MoreOptions : IOptions
6+
public class RegisterCommands : AbstractPlugin
97
{
108
[VerbOption("sample:show-progress", HelpText = "A sample command to demonstrate the progress bar.")]
119
public ShowProgress ShowProgress { get; set; }
@@ -15,11 +13,5 @@ public class MoreOptions : IOptions
1513

1614
[VerbOption("sample:minimal")]
1715
public Minimal Minimal { get; set; }
18-
19-
[HelpVerbOption]
20-
public string GetUsage(string verb)
21-
{
22-
return HelpText.AutoBuild(this, verb);
23-
}
2416
}
2517
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using CommandLine;
3+
using CommandLine.Text;
4+
5+
namespace InEngine.Core
6+
{
7+
public class AbstractPlugin : IPluginType
8+
{
9+
[HelpVerbOption]
10+
public virtual string GetUsage(string verb)
11+
{
12+
return HelpText.AutoBuild(this, verb);
13+
}
14+
}
15+
}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
using CommandLine;
2-
using CommandLine.Text;
32

43
namespace InEngine.Core.Commands
54
{
6-
public class Options : IOptions
5+
public class CommandPlugin : AbstractPlugin
76
{
87
[VerbOption("echo", HelpText= "Echo some text to the console. Useful for end-to-end testing.")]
98
public Echo Echo { get; set; }
109

1110
[VerbOption("proc", HelpText = "Launch an arbitrary process.")]
1211
public SystemProcess SystemProcess { get; set; }
13-
14-
[HelpVerbOption]
15-
public string GetUsage(string verb)
16-
{
17-
return HelpText.AutoBuild(this, verb);
18-
}
1912
}
2013
}

src/InEngine.Core/IOptions.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/InEngine.Core/Plugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public AbstractCommand CreateCommandFromClass(string fullCommandName)
8282
public AbstractCommand CreateCommandFromVerb(string verbName)
8383
{
8484
var commandClassNames = new List<string>();
85-
var optionsList = Make<IOptions>();
85+
var optionsList = Make<AbstractPlugin>();
8686

8787
foreach (var options in optionsList)
8888
foreach (var property in options.GetType().GetProperties())

src/InEngine.Core/Queuing/Options.cs renamed to src/InEngine.Core/Queuing/Commands/RegisterCommands.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using CommandLine;
22
using CommandLine.Text;
3-
using InEngine.Core.Queuing.Commands;
43

5-
namespace InEngine.Core.Queuing
4+
namespace InEngine.Core.Queuing.Commands
65
{
7-
public class Options : IOptions
6+
public class RegisterCommands : AbstractPlugin
87
{
98
[VerbOption("queue:publish", HelpText = "Publish a command commandEnvelope to a queue.")]
109
public Publish Publish { get; set; }
@@ -23,11 +22,5 @@ public class Options : IOptions
2322

2423
[VerbOption("queue:peek", HelpText = "Peek at messages in the primary or secondary queues.")]
2524
public Peek Peek { get; set; }
26-
27-
[HelpVerbOption]
28-
public string GetUsage(string verb)
29-
{
30-
return HelpText.AutoBuild(this, verb);
31-
}
3225
}
3326
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Linq;
3+
using InEngine.Core.Queuing.Commands;
4+
using InEngine.Core.Scheduling;
5+
6+
namespace InEngine.Core.Queuing
7+
{
8+
public class QueuingPlugin : AbstractPlugin
9+
{
10+
public void Schedule(ISchedule schedule)
11+
{
12+
var queueSettings = InEngineSettings.Make().Queue;
13+
ScheduleQueueConsumerJobs(schedule, queueSettings.PrimaryQueueConsumers);
14+
ScheduleQueueConsumerJobs(schedule, queueSettings.SecondaryQueueConsumers, true);
15+
}
16+
17+
void ScheduleQueueConsumerJobs(ISchedule schedule, int consumers, bool useSecondaryQueue = false)
18+
{
19+
if (consumers < 0)
20+
throw new ArgumentOutOfRangeException(nameof(consumers), consumers, "The number of queue consumers must be 0 or greater.");
21+
22+
foreach (var index in Enumerable.Range(0, consumers).ToList())
23+
schedule.Command(new Consume()
24+
{
25+
ScheduleId = $"{(useSecondaryQueue ? "secondary" : "primary")}:{index.ToString()}",
26+
UseSecondaryQueue = useSecondaryQueue
27+
})
28+
.EverySecond();
29+
}
30+
}
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using CommandLine;
2+
3+
namespace InEngine.Core.Scheduling
4+
{
5+
public class CommandsPlugin : AbstractPlugin
6+
{
7+
[VerbOption("schedule:list", HelpText = "List all scheduled jobs.")]
8+
public ListScheduledCommands ListScheduledCommands { get; set; }
9+
}
10+
}

src/InEngine.Core/Scheduling/Options.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)