// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AutomationTool
{
///
/// Base class for buildcommands.
///
public abstract class BuildCommand : CommandUtils
{
///
/// Command line parameters for this command (empty by non-null by default)
///
private string[] CommandLineParams = new string[0];
public string[] Params
{
get { return CommandLineParams; }
set { CommandLineParams = value; }
}
///
/// Parses the command's Params list for a parameter and returns whether it is defined or not.
///
/// Param to check for.
/// True if param was found, false otherwise.
public bool ParseParam(string Param)
{
return ParseParam(Params, Param);
}
///
/// Parses the command's Params list for a parameter and reads its value.
/// Ex. ParseParamValue(Args, "map=")
///
/// Param to read its value.
/// Returns the value or Default if the parameter was not found.
public string ParseParamValue(string Param, string Default = null)
{
return ParseParamValue(Params, Param, Default);
}
///
/// Parses the argument list for any number of parameters.
///
/// Argument list.
/// Param to read its value.
/// Returns an array of values for this parameter (or an empty array if one was not found.
public string[] ParseParamValues(string Param)
{
return ParseParamValues(Params, Param);
}
///
/// Parses the command's Params list for a parameter and reads its value.
/// Ex. ParseParamValue(Args, "map=")
///
/// Param to read its value.
/// Returns the value or Default if the parameter was not found.
public int ParseParamInt(string Param, int Default = 0)
{
string num = ParseParamValue(Params, Param, Default.ToString());
return int.Parse(num);
}
///
/// Parses the command's Params list for a parameter and reads its value.
/// Ex. ParseParamValue(Args, "map=")
///
/// Param to read its value.
/// Returns the value or Default if the parameter was not found.
public int? ParseParamNullableInt(string Param)
{
string Value = ParseParamValue(Params, Param, null);
if(Value == null)
{
return null;
}
else
{
return int.Parse(Value);
}
}
///
/// Build command entry point. Throws AutomationExceptions on failure.
///
public virtual void ExecuteBuild()
{
throw new AutomationException("Either Execute() or ExecuteBuild() should be implemented for {0}", GetType().Name);
}
///
/// Command entry point.
///
public virtual ExitCode Execute()
{
ExecuteBuild();
return ExitCode.Success;
}
///
/// Executes a new command as a child of another command.
///
///
///
public static ExitCode Execute(BuildCommand ParentCommand) where T : BuildCommand, new()
{
T Command = new T();
if (ParentCommand != null)
{
Command.Params = ParentCommand.Params;
}
return Command.Execute();
}
}
}