mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Feature, Help] Add unhooked help features
This commit is contained in:
@@ -8,7 +8,7 @@ namespace SabreTools.Library.Help
|
|||||||
{
|
{
|
||||||
public class Feature
|
public class Feature
|
||||||
{
|
{
|
||||||
#region Private variables
|
#region Private instance variables
|
||||||
|
|
||||||
private List<string> _flags;
|
private List<string> _flags;
|
||||||
private string _description;
|
private string _description;
|
||||||
@@ -17,6 +17,11 @@ namespace SabreTools.Library.Help
|
|||||||
private List<string> _additionalNotes;
|
private List<string> _additionalNotes;
|
||||||
private bool _foundOnce = false;
|
private bool _foundOnce = false;
|
||||||
|
|
||||||
|
// Specific value types
|
||||||
|
private bool _valueBool = false;
|
||||||
|
private string _valueString = null;
|
||||||
|
private List<string> _valueList = null;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@@ -342,12 +347,33 @@ namespace SabreTools.Library.Help
|
|||||||
// If we have a flag, make sure it doesn't have an equal sign in it
|
// If we have a flag, make sure it doesn't have an equal sign in it
|
||||||
case FeatureType.Flag:
|
case FeatureType.Flag:
|
||||||
valid = !input.Contains("=") && _flags.Contains(input);
|
valid = !input.Contains("=") && _flags.Contains(input);
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
_valueBool = true;
|
||||||
|
_foundOnce = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// If we have an input, make sure it has an equals sign in it
|
// If we have an input, make sure it has an equals sign in it
|
||||||
case FeatureType.List:
|
case FeatureType.List:
|
||||||
|
valid = input.Contains("=") && _flags.Contains(input.Split('=')[0]);
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
if (_valueList == null)
|
||||||
|
{
|
||||||
|
_valueList = new List<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
_valueList.Add(input.Split('=')[1]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case FeatureType.String:
|
case FeatureType.String:
|
||||||
valid = input.Contains("=") && _flags.Contains(input.Split('=')[0]);
|
valid = input.Contains("=") && _flags.Contains(input.Split('=')[0]);
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
_valueString = input.Split('=')[1];
|
||||||
|
_foundOnce = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,6 +407,46 @@ namespace SabreTools.Library.Help
|
|||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the proper value associated with this feature
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Value associated with this feature</returns>
|
||||||
|
public object GetValue()
|
||||||
|
{
|
||||||
|
switch (_featureType)
|
||||||
|
{
|
||||||
|
case FeatureType.Flag:
|
||||||
|
return _valueBool;
|
||||||
|
case FeatureType.List:
|
||||||
|
return _valueList;
|
||||||
|
case FeatureType.String:
|
||||||
|
return _valueString;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns if this feature has a valid value or not
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if the feature is enabled, false otherwise</returns>
|
||||||
|
public bool IsEnabled()
|
||||||
|
{
|
||||||
|
object obj = GetValue();
|
||||||
|
|
||||||
|
switch (_featureType)
|
||||||
|
{
|
||||||
|
case FeatureType.Flag:
|
||||||
|
return (bool)obj;
|
||||||
|
case FeatureType.List:
|
||||||
|
return obj != null;
|
||||||
|
case FeatureType.String:
|
||||||
|
return obj != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using SabreTools.Library.Data;
|
||||||
|
|
||||||
namespace SabreTools.Library.Help
|
namespace SabreTools.Library.Help
|
||||||
{
|
{
|
||||||
// TODO: Parse and return flags from arguments
|
// TODO: Parse and return flags from arguments
|
||||||
@@ -253,6 +255,47 @@ namespace SabreTools.Library.Help
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve a list of enabled features
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>List of Features representing what is enabled</returns>
|
||||||
|
public List<Feature> GetEnabledFeatures()
|
||||||
|
{
|
||||||
|
List<Feature> enabled = new List<Feature>();
|
||||||
|
|
||||||
|
// Loop through the features
|
||||||
|
foreach(KeyValuePair<string, Feature> feature in _features)
|
||||||
|
{
|
||||||
|
enabled.AddRange(GetEnabledSubfeatures(feature.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve a nested list of subfeatures from the current feature
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="feature">Feature with possible subfeatures to test</param>
|
||||||
|
/// <returns>List of Features representing what is enabled</returns>
|
||||||
|
private List<Feature> GetEnabledSubfeatures(Feature feature)
|
||||||
|
{
|
||||||
|
List<Feature> enabled = new List<Feature>();
|
||||||
|
|
||||||
|
// First determine if the current feature is enabled
|
||||||
|
if (feature.IsEnabled())
|
||||||
|
{
|
||||||
|
enabled.Add(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now loop through the subfeatures recursively
|
||||||
|
foreach (KeyValuePair<string, Feature> sub in _features)
|
||||||
|
{
|
||||||
|
enabled.AddRange(GetEnabledSubfeatures(sub.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out the help text with pauses, if needed
|
/// Write out the help text with pauses, if needed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user