BadScript 2
Loading...
Searching...
No Matches
BadConsoleSystem.cs
Go to the documentation of this file.
2
3using CommandLine;
4
6
11public abstract class BadConsoleSystem<T> : BadAConsoleSystem
12{
17 protected BadConsoleSystem(BadRuntime runtime) : base(runtime) { }
18
20 public override Task<int> Run(object? settings)
21 {
22 if (settings is T t)
23 {
24 return Run(t);
25 }
26
27 BadConsole.WriteLine(settings is null ? "No settings provided." : "Invalid settings type");
28
29 return Task.FromResult(-1);
30 }
31
33 public override object? Parse(string[] args)
34 {
35 CommandLine.Parser parser = new CommandLine.Parser(() => ParserSettings.CreateDefault(ParserSettings.DefaultMaximumLength));
36 T t = parser.ParseArguments<T>(args).Value;
37
38 if (t is null)
39 {
40 return null;
41 }
42
43 return t;
44 }
45
51 protected abstract Task<int> Run(T settings);
52}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:28
Wrapper class for the console abstraction.
Definition BadConsole.cs:12
static void WriteLine(string str)
Writes a string to the console and appends a newline.
Definition BadConsole.cs:76
Implements a the base features of a Console System.
Implements a Console System that uses a settings object of Type T.
override Task< int > Run(object? settings)
Task< int > Run(T settings)
Runs the Console System with the given settings.
BadConsoleSystem(BadRuntime runtime)
Creates a new BadConsoleSystem instance.
Contains a Console Abstraction Layer to be able to Simulate Console Input/Output over the Network.
Definition BadConsole.cs:6
Contains the Console Subsystems of the Console Application.