Fix some formatting issues with Input types

This commit is contained in:
Matt Nadareski
2024-12-04 23:08:17 -05:00
parent c7c700e567
commit 5392afbf06
13 changed files with 70 additions and 79 deletions

View File

@@ -31,6 +31,7 @@
- Add self-formatting to Input types
- Handle issue with old .NET
- Let inputs read equal-separated values
- Fix some formatting issues with Input types
### 3.2.4 (2024-11-24)

View File

@@ -38,10 +38,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Separator
if (useEquals)
@@ -63,7 +60,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -85,7 +82,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');

View File

@@ -38,10 +38,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
return builder.ToString();
}
@@ -54,7 +51,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check the name
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
Value = true;
return true;

View File

@@ -15,20 +15,20 @@ namespace MPF.ExecutionContexts.Data
public readonly string Name;
/// <summary>
/// Indicates if a value has been set
/// Short name for the input
/// </summary>
public abstract bool ValueSet { get; }
/// <summary>
/// Verbose name for the input
/// </summary>
protected readonly string? _longName;
protected readonly string? _shortName;
/// <summary>
/// Indicates if the value following is required or not
/// </summary>
protected readonly bool _required;
/// <summary>
/// Indicates if a value has been set
/// </summary>
public abstract bool ValueSet { get; }
#endregion
#region Constructors
@@ -37,7 +37,7 @@ namespace MPF.ExecutionContexts.Data
public Input(string name)
{
Name = name;
_longName = null;
_shortName = null;
_required = true;
}
@@ -46,7 +46,7 @@ namespace MPF.ExecutionContexts.Data
public Input(string name, bool required)
{
Name = name;
_longName = null;
_shortName = null;
_required = required;
}
@@ -54,8 +54,8 @@ namespace MPF.ExecutionContexts.Data
/// <param name="longName">Verbose flag name / value</param>
public Input(string shortName, string longName)
{
Name = shortName;
_longName = longName;
Name = longName;
_shortName = shortName;
_required = true;
}
@@ -64,8 +64,8 @@ namespace MPF.ExecutionContexts.Data
/// <param name="required">Indicates if a following value is required</param>
public Input(string shortName, string longName, bool required)
{
Name = shortName;
_longName = longName;
Name = longName;
_shortName = shortName;
_required = required;
}
@@ -73,6 +73,11 @@ namespace MPF.ExecutionContexts.Data
#region Functionality
/// <summary>
/// Clear any accumulated value
/// </summary>
public abstract void ClearValue();
/// <summary>
/// Create a formatted representation of the input and possible value
/// </summary>
@@ -209,5 +214,23 @@ namespace MPF.ExecutionContexts.Data
: base(shortName, longName, required) { }
#endregion
#region Functionality
/// <inheritdoc/>
public override void ClearValue()
{
Value = default;
}
/// <summary>
/// Set a new value
/// </summary>
public void SetValue(T value)
{
Value = value;
}
#endregion
}
}

View File

@@ -43,10 +43,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Only output separator and value if needed
if (_required || (!_required && Value != short.MinValue))
@@ -72,7 +69,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -95,7 +92,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');

View File

@@ -43,10 +43,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Only output separator and value if needed
if (_required || (!_required && Value != int.MinValue))
@@ -72,7 +69,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -95,7 +92,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');

View File

@@ -43,10 +43,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Only output separator and value if needed
if (_required || (!_required && Value != long.MinValue))
@@ -72,7 +69,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -95,7 +92,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');

View File

@@ -43,10 +43,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Only output separator and value if needed
if (_required || (!_required && Value != sbyte.MinValue))
@@ -72,7 +69,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -95,7 +92,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');

View File

@@ -42,10 +42,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Only output separator and value if needed
if (_required || (!_required && Value != string.Empty))
@@ -57,7 +54,7 @@ namespace MPF.ExecutionContexts.Data
builder.Append(" ");
// Value
builder.Append(Value.ToString());
builder.Append($"\"{Value}\"");
}
return builder.ToString();
@@ -71,7 +68,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -86,7 +83,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');

View File

@@ -43,10 +43,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Only output separator and value if needed
if (_required || (!_required && Value != ushort.MinValue))
@@ -72,7 +69,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -95,7 +92,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');

View File

@@ -43,10 +43,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Only output separator and value if needed
if (_required || (!_required && Value != uint.MinValue))
@@ -72,7 +69,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -95,7 +92,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');

View File

@@ -43,10 +43,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Only output separator and value if needed
if (_required || (!_required && Value != ulong.MinValue))
@@ -72,7 +69,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -95,7 +92,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');

View File

@@ -43,10 +43,7 @@ namespace MPF.ExecutionContexts.Data
var builder = new StringBuilder();
// Flag name
if (_longName != null)
builder.Append(_longName);
else
builder.Append(Name);
builder.Append(Name);
// Only output separator and value if needed
if (_required || (!_required && Value != byte.MinValue))
@@ -72,7 +69,7 @@ namespace MPF.ExecutionContexts.Data
return false;
// Check for space-separated
if (parts[index] == Name || (_longName != null && parts[index] == _longName))
if (parts[index] == Name || (_shortName != null && parts[index] == _shortName))
{
// Ensure the value exists
if (index + 1 >= parts.Length)
@@ -95,7 +92,7 @@ namespace MPF.ExecutionContexts.Data
}
// Check for equal separated
if (parts[index].StartsWith($"{Name}=") || (_longName != null && parts[index].StartsWith($"{_longName}=")))
if (parts[index].StartsWith($"{Name}=") || (_shortName != null && parts[index].StartsWith($"{_shortName}=")))
{
// Split the string, using the first equal sign as the separator
string[] tempSplit = parts[index].Split('=');