using System;
using System.Collections.Generic;
using System.IO;
using SabreTools.Library.Data;
namespace SabreTools.Library.Help
{
///
/// Represents an actionable top-level feature
///
public abstract class TopLevel : Feature
{
public List Inputs = new List();
///
/// Process args list based on current feature
///
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]))
{
// Special precautions for files and directories
if (File.Exists(args[i]) || Directory.Exists(args[i]))
{
Inputs.Add(args[i]);
}
// Special precautions for wildcarded inputs (potential paths)
else if (args[i].Contains("*") || args[i].Contains("?"))
{
Inputs.Add(args[i]);
}
// Everything else isn't a file
else
{
Globals.Logger.Error($"Invalid input detected: {args[i]}");
help.OutputIndividualFeature(this.Name);
Globals.Logger.Close();
return false;
}
}
}
return true;
}
///
/// Process and extract variables based on current feature
///
public virtual void ProcessFeatures(Dictionary features) { }
#region Generic Extraction
///
/// Get boolean value from nullable feature
///
protected bool GetBoolean(Dictionary features, string key)
{
if (!features.ContainsKey(key))
return false;
return true;
}
///
/// Get int value from nullable feature
///
protected int GetInt32(Dictionary features, string key)
{
if (!features.ContainsKey(key))
return Int32.MinValue;
return features[key].GetInt32Value();
}
///
/// Get long value from nullable feature
///
protected long GetInt64(Dictionary features, string key)
{
if (!features.ContainsKey(key))
return Int64.MinValue;
return features[key].GetInt64Value();
}
///
/// Get list value from nullable feature
///
protected List GetList(Dictionary features, string key)
{
if (!features.ContainsKey(key))
return new List();
return features[key].GetListValue() ?? new List();
}
///
/// Get string value from nullable feature
///
protected string GetString(Dictionary features, string key)
{
if (!features.ContainsKey(key))
return null;
return features[key].GetStringValue();
}
#endregion
}
}