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 =
37
38 T t = parser.ParseArguments<T>(args)
39 .Value;
40
41 if (t is null)
42 {
43 return null;
44 }
45
46 return t;
47 }
48
54 protected abstract Task<int> Run(T settings);
55}
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:30
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:78
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.
Provides methods to parse command line arguments.
Definition Parser.cs:21
ParserResult< object > ParseArguments(IEnumerable< string > args, params Type[] types)
Parses a string array of command line arguments for verb commands scenario, constructing the proper i...
Definition Parser.cs:216
Provides settings for CommandLine.Parser. Once consumed cannot be reused.
static ParserSettings CreateDefault(int? maxDisplayWidth=null)
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.