using System.Collections.Generic;
namespace SRML.Console.Commands
{
///
/// A command to add a user defined button to the command menu
///
public class AddButtonCommand : ConsoleCommand
{
public override string ID { get; } = "addbutton";
public override string Usage { get; } = "addbutton ";
public override string Description { get; } = "Adds a user defined button to the command menu";
public override string ExtendedDescription =>
" - The id of the button. 'all' is not a valid id\n" +
" - The text to display on the button\n" +
" - The command the button will execute";
public override bool Execute(string[] args)
{
if (args == null)
{
Console.LogError($"The '{ID}' command takes 3 arguments");
return false;
}
if (ArgsOutOfBounds(args.Length, 3, 3))
return false;
if (args[0].Contains(" "))
{
Console.LogError($"The '' argument cannot contain any spaces");
return false;
}
if (args[0].Equals("all"))
{
Console.LogWarning($"Trying to register user defined button with id 'all' but 'all' is not a valid id!");
return false;
}
if (Console.cmdButtons.ContainsKey("user." + args[0]))
{
Console.LogWarning($"Trying to register user defined button with id '{args[0]}' but the ID is already registered!");
return false;
}
ConsoleBinder.RegisterBind(args[0], args[1], args[2]);
Console.LogSuccess($"Added new user defined button '{args[0]}' with command '{args[2]}'");
return true;
}
public override List GetAutoComplete(int argIndex, string argText)
{
if (argIndex == 2)
return new List(Console.commands.Keys);
else
return base.GetAutoComplete(argIndex, argText);
}
}
}