2020-06-10 22:37:19 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
2020-10-07 15:42:30 -07:00
|
|
|
|
using SabreTools.Library.Logging;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Library.Help
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents an actionable top-level feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract class TopLevel : Feature
|
|
|
|
|
|
{
|
|
|
|
|
|
public List<string> Inputs = new List<string>();
|
|
|
|
|
|
|
2020-10-07 15:42:30 -07:00
|
|
|
|
#region Logging
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Logging object
|
|
|
|
|
|
/// </summary>
|
2020-10-07 16:11:05 -07:00
|
|
|
|
private readonly Logger logger = new Logger();
|
2020-10-07 15:42:30 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Process args list based on current feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual bool ProcessArgs(string[] args, Help help)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 1; i < args.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Verify that the current flag is proper for the feature
|
|
|
|
|
|
if (!ValidateInput(args[i]))
|
|
|
|
|
|
{
|
2020-08-17 14:37:37 -07:00
|
|
|
|
// Special precautions for files and directories
|
|
|
|
|
|
if (File.Exists(args[i]) || Directory.Exists(args[i]))
|
|
|
|
|
|
{
|
|
|
|
|
|
Inputs.Add(args[i]);
|
|
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-17 14:37:37 -07:00
|
|
|
|
// Special precautions for wildcarded inputs (potential paths)
|
|
|
|
|
|
else if (args[i].Contains("*") || args[i].Contains("?"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Inputs.Add(args[i]);
|
|
|
|
|
|
}
|
2020-08-08 21:53:34 -07:00
|
|
|
|
|
2020-08-17 14:37:37 -07:00
|
|
|
|
// Everything else isn't a file
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error($"Invalid input detected: {args[i]}");
|
2020-08-17 14:37:37 -07:00
|
|
|
|
help.OutputIndividualFeature(this.Name);
|
2020-10-07 15:42:30 -07:00
|
|
|
|
LoggerImpl.Close();
|
2020-08-17 14:37:37 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Process and extract variables based on current feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual void ProcessFeatures(Dictionary<string, Feature> features) { }
|
|
|
|
|
|
|
|
|
|
|
|
#region Generic Extraction
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get boolean value from nullable feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected bool GetBoolean(Dictionary<string, Feature> features, string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get int value from nullable feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected int GetInt32(Dictionary<string, Feature> features, string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return Int32.MinValue;
|
|
|
|
|
|
|
|
|
|
|
|
return features[key].GetInt32Value();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get long value from nullable feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected long GetInt64(Dictionary<string, Feature> features, string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return Int64.MinValue;
|
|
|
|
|
|
|
|
|
|
|
|
return features[key].GetInt64Value();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get list value from nullable feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected List<string> GetList(Dictionary<string, Feature> features, string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
return features[key].GetListValue() ?? new List<string>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get string value from nullable feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected string GetString(Dictionary<string, Feature> features, string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
return features[key].GetStringValue();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|