User Tools

Site Tools


Sidebar

Nebol Software Projects:

.NET Class Libraries

Contact info:

johan@nebol.se

nebolintegration_console_commands

NebolIntegration: NebolIntegration_Console_Commands - Utilising the built-in console commands

NebolIntegration supports NebolCommand and has a built-in command set ready for use.

NOTE: This functionality has been moved into its own class library: NebolIntegration.Console

Use like this:

public static Parser SetupParser()
{
	// get the built-in commands
	var commands = new Commands(engine, config); 
 
	var parser = new Parser();
 
	// add the commands from the Commands class
	parser.Commands.AddRange(commands.CommandList);
 
	// I'm adding an extra command, for exiting the application
	parser.Commands.Add(new Command
	{
		Name = "exit",
		AlternateName = "x",
		ShortDescription = "exit the application gracefully",
		ExecuteDelegate = new ExecuteDelegate(item => Quit())
	});
 
	return (parser);
}

Main loop:

var parser = SetupParser();
 
Console.WriteLine("Ready. Type ? for help.");
 
while (!shutdown)
{
	Console.Write("> ");
	string s = Console.ReadLine();
 
	if (string.IsNullOrEmpty(s))
		Console.WriteLine("Type help to list all commands.");
	else
		parser.Parse(s);
}
public static void Quit()
{
	shutdown = true;

	Console.WriteLine("Shutting down of application has begun...");
}
nebolintegration_console_commands.txt · Last modified: 2022/06/09 22:23 by nebol