Slight cleanup of Help

This commit is contained in:
Matt Nadareski
2024-07-18 00:32:41 -04:00
parent c286d40695
commit 0a5f6f2b15
3 changed files with 32 additions and 50 deletions

View File

@@ -17,10 +17,10 @@ namespace SabreTools.Help
#region Publicly facing variables
public string? Name { get; protected set; }
public List<string> Flags { get; protected set; }
public readonly List<string> Flags = [];
public string? Description { get; protected set; }
public string? LongDescription { get; protected set; }
public Dictionary<string, Feature?> Features { get; protected set; }
public readonly Dictionary<string, Feature?> Features = [];
#endregion
@@ -28,35 +28,28 @@ namespace SabreTools.Help
public Feature()
{
_featureType = ParameterType.Flag;
Name = null;
Flags = [];
Description = null;
LongDescription = null;
_featureType = ParameterType.Flag;
Features = [];
}
public Feature(string name, string flag, string description, ParameterType featureType, string? longDescription = null)
{
_featureType = featureType;
Name = name;
Flags =
[
flag
];
Flags.Add(flag);
Description = description;
LongDescription = longDescription;
_featureType = featureType;
Features = [];
}
public Feature(string name, List<string> flags, string description, ParameterType featureType, string? longDescription = null)
{
_featureType = featureType;
Name = name;
Flags = flags;
Flags.AddRange(flags);
Description = description;
LongDescription = longDescription;
_featureType = featureType;
Features = [];
}
#endregion
@@ -87,7 +80,6 @@ namespace SabreTools.Help
/// <param name="feature"></param>
public void AddFeature(Feature feature)
{
Features ??= [];
lock (Features)
{
Features[feature.Name ?? string.Empty] = feature;
@@ -100,7 +92,6 @@ namespace SabreTools.Help
/// <param name="flag">Flag to add for this feature</param>
public void AddFlag(string flag)
{
Flags ??= [];
lock (Flags)
{
Flags.Add(flag);
@@ -113,7 +104,6 @@ namespace SabreTools.Help
/// <param name="flags">List of flags to add to this feature</param>
public void AddFlags(List<string> flags)
{
Flags ??= [];
lock (Flags)
{
Flags.AddRange(flags);
@@ -281,7 +271,7 @@ namespace SabreTools.Help
public List<string> OutputRecursive(int tabLevel, int pre = 0, int midpoint = 0, bool includeLongDescription = false)
{
// Create the output list
List<string> outputList = new();
List<string> outputList = [];
// Build the output string first
string output = string.Empty;

View File

@@ -8,8 +8,8 @@ namespace SabreTools.Help
{
#region Private variables
private readonly List<string> _header;
private Dictionary<string, Feature?> _features;
private readonly List<string> _header = [];
private readonly Dictionary<string, Feature?> _features = [];
private const string _barrier = "-----------------------------------------";
#endregion
@@ -18,14 +18,11 @@ namespace SabreTools.Help
public FeatureSet()
{
_header = [];
_features = [];
}
public FeatureSet(List<string> header)
{
_header = header;
_features = [];
_header.AddRange(header);
}
#endregion
@@ -36,7 +33,6 @@ namespace SabreTools.Help
{
get
{
_features ??= [];
if (!_features.ContainsKey(name))
return null;
@@ -44,7 +40,6 @@ namespace SabreTools.Help
}
set
{
_features ??= [];
_features[name] = value;
}
}
@@ -56,7 +51,6 @@ namespace SabreTools.Help
if (subfeature.Name == null)
return null;
_features ??= [];
if (!_features.ContainsKey(subfeature.Name))
return null;
@@ -64,7 +58,6 @@ namespace SabreTools.Help
}
set
{
_features ??= [];
if (subfeature.Name != null)
_features[subfeature.Name] = value;
}
@@ -79,7 +72,6 @@ namespace SabreTools.Help
if (feature.Name == null)
return;
_features ??= [];
lock (_features)
{
_features.Add(feature.Name, feature);

View File

@@ -15,7 +15,7 @@ namespace SabreTools.Help
/// <summary>
/// List of files, directories, and potential wildcard paths
/// </summary>
public List<string> Inputs = [];
public readonly List<string> Inputs = [];
#endregion
@@ -50,12 +50,13 @@ namespace SabreTools.Help
for (int i = 1; i < args.Length; i++)
{
// Verify that the current flag is proper for the feature
if (!ValidateInput(args[i]))
{
if (ValidateInput(args[i]))
continue;
// Special precautions for files and directories
if (File.Exists(args[i]) || Directory.Exists(args[i]))
{
Inputs.Add(args[i]);
Inputs.Add(item: args[i]);
}
// Special precautions for wildcarded inputs (potential paths)
@@ -77,7 +78,6 @@ namespace SabreTools.Help
return false;
}
}
}
return true;
}