2020-06-10 22:37:19 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
2020-12-07 14:29:45 -08:00
|
|
|
|
using SabreTools.Logging;
|
|
|
|
|
|
|
2020-12-07 13:57:26 -08:00
|
|
|
|
namespace SabreTools.Help
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents an actionable top-level feature
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract class TopLevel : Feature
|
|
|
|
|
|
{
|
2020-10-07 16:37:10 -07:00
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// List of files, directories, and potential wildcard paths
|
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
|
public List<string> Inputs = new();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-10-07 16:37:10 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-10-07 15:42:30 -07:00
|
|
|
|
#region Logging
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Logging object
|
|
|
|
|
|
/// </summary>
|
2020-12-07 14:29:45 -08:00
|
|
|
|
private readonly Logger logger;
|
2020-10-07 16:37:10 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public TopLevel()
|
|
|
|
|
|
{
|
2020-12-07 14:29:45 -08:00
|
|
|
|
logger = new Logger(this);
|
2020-10-07 16:37:10 -07:00
|
|
|
|
}
|
2020-10-07 15:42:30 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-10-07 16:37:10 -07:00
|
|
|
|
#region Processing
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Process args list based on current feature
|
|
|
|
|
|
/// </summary>
|
2020-12-08 17:05:08 -08:00
|
|
|
|
public virtual bool ProcessArgs(string[] args, FeatureSet help)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
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)
|
2023-04-19 16:39:58 -04:00
|
|
|
|
else if (args[i].Contains('*') || args[i].Contains('?'))
|
2020-08-17 14:37:37 -07:00
|
|
|
|
{
|
|
|
|
|
|
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-12-07 14:29:45 -08:00
|
|
|
|
logger.Error($"Invalid input detected: {args[i]}");
|
2020-08-17 14:37:37 -07:00
|
|
|
|
help.OutputIndividualFeature(this.Name);
|
2020-12-07 14:29:45 -08: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>
|
2021-03-19 20:52:11 -07:00
|
|
|
|
/// <returns>True if execution was successful, false otherwise</returns>
|
|
|
|
|
|
public virtual bool ProcessFeatures(Dictionary<string, Feature> features) => true;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-10-07 16:37:10 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
#region Generic Extraction
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get boolean value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
|
protected static bool GetBoolean(Dictionary<string, Feature> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get int value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
|
protected static int GetInt32(Dictionary<string, Feature> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return Int32.MinValue;
|
|
|
|
|
|
|
|
|
|
|
|
return features[key].GetInt32Value();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get long value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
|
protected static long GetInt64(Dictionary<string, Feature> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return Int64.MinValue;
|
|
|
|
|
|
|
|
|
|
|
|
return features[key].GetInt64Value();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get list value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
|
protected static List<string> GetList(Dictionary<string, Feature> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
return features[key].GetListValue() ?? new List<string>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get string value from nullable feature
|
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
|
protected static string GetString(Dictionary<string, Feature> features, string key)
|
2020-06-10 22:37:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (!features.ContainsKey(key))
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
return features[key].GetStringValue();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|