BadScript 2
Loading...
Searching...
No Matches
BadConsoleRunner.cs
Go to the documentation of this file.
3
5
9public class BadConsoleRunner
10{
14 private readonly BadAConsoleSystem m_Default;
15
19 private readonly BadAConsoleSystem[] m_Systems;
20
26 public BadConsoleRunner(BadAConsoleSystem @default, params BadAConsoleSystem[] systems)
27 {
28 m_Default = @default;
29 m_Systems = systems;
30 }
31
37 public Task<int> Run(string[] args)
38 {
39 while (args.Length == 0)
40 {
41 BadConsole.WriteLine("No command specified.");
42 BadConsole.WriteLine("Usage: bs <system> [args]");
43 BadConsole.WriteLine("Available systems:");
44
45 foreach (BadAConsoleSystem sys in m_Systems)
46 {
47 BadConsole.WriteLine($"\t{sys.Name}");
48 }
49
50 BadConsole.Write("Input start arguments: ");
51
52 args = BadConsole.ReadLine().Split(' ');
53 }
54
55 string name = args[0];
56 BadAConsoleSystem? system = m_Systems.FirstOrDefault(x => x.Name == name);
57
58 return system?.Run(system.Parse(args.Skip(1).ToArray())) ?? m_Default.Run(m_Default.Parse(args));
59 }
60}
Wrapper class for the console abstraction.
Definition BadConsole.cs:12
static string ReadLine()
Reads a line from the console.
Definition BadConsole.cs:85
static void Write(string str)
Writes a string to the console.
Definition BadConsole.cs:67
static void WriteLine(string str)
Writes a string to the console and appends a newline.
Definition BadConsole.cs:76
Class that can register console systems and run them.
BadConsoleRunner(BadAConsoleSystem @default, params BadAConsoleSystem[] systems)
Constructor.
Task< int > Run(string[] args)
Runs a system with the specified arguments.
readonly BadAConsoleSystem[] m_Systems
The Systems that are registered.
readonly BadAConsoleSystem m_Default
The Default system that is beeing used if the user does not specify a system.
Implements a the base features of a Console System.
Task< int > Run(object? settings)
Runs the Console System with the given settings.
object? Parse(string[] args)
Parses the given arguments into a settings object.
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.
Contains the Core Functionality of the Console Application.