Remove duplicate input declarations

This commit is contained in:
Matt Nadareski
2025-10-06 16:34:19 -04:00
parent 4a3c585a8d
commit baffdb8b29
5 changed files with 127 additions and 205 deletions

View File

@@ -13,6 +13,7 @@
- Create and use base feature in Check
- Create and use base feature in CLI
- Assign inputs for interactive modes
- Remove duplicate input declarations
### 3.4.2 (2025-09-30)

View File

@@ -16,32 +16,32 @@ namespace MPF.CLI.Features
private static readonly string[] _flags = [];
/// <remarks>Description is unused</remarks>
internal const string _description = "";
private const string _description = "";
#endregion
#region Inputs
private const string _customName = "custom";
private static readonly StringInput _customInput = new(_customName, ["-c", "--custom"], "Custom parameters to use");
internal readonly StringInput CustomInput = new(_customName, ["-c", "--custom"], "Custom parameters to use");
private const string _deviceName = "device";
private static readonly StringInput _deviceInput = new(_deviceName, ["-d", "--device"], "Physical drive path (Required if no custom parameters set)");
internal readonly StringInput DeviceInput = new(_deviceName, ["-d", "--device"], "Physical drive path (Required if no custom parameters set)");
private const string _fileName = "file";
private static readonly StringInput _fileInput = new(_fileName, ["-f", "--file"], "Output file path (Required if no custom parameters set)");
internal readonly StringInput FileInput = new(_fileName, ["-f", "--file"], "Output file path (Required if no custom parameters set)");
private const string _mediaTypeName = "media-type";
private static readonly StringInput _mediaTypeInput = new(_mediaTypeName, ["-t", "--mediatype"], "Set media type for dumping (Required for DIC)");
internal readonly StringInput MediaTypeInput = new(_mediaTypeName, ["-t", "--mediatype"], "Set media type for dumping (Required for DIC)");
private const string _mountedName = "mounted";
private static readonly StringInput _mountedInput = new(_mountedName, ["-m", "--mounted"], "Mounted filesystem path for additional checks");
internal readonly StringInput MountedInput = new(_mountedName, ["-m", "--mounted"], "Mounted filesystem path for additional checks");
private const string _speedName = "speed";
private static readonly Int32Input _speedInput = new(_speedName, ["-s", "--speed"], "Override default dumping speed");
internal readonly Int32Input SpeedInput = new(_speedName, ["-s", "--speed"], "Override default dumping speed");
private const string _useName = "use";
private static readonly StringInput _useInput = new(_useName, ["-u", "--use"], "Override configured dumping program name");
internal readonly StringInput UseInput = new(_useName, ["-u", "--use"], "Override configured dumping program name");
#endregion
@@ -76,13 +76,13 @@ namespace MPF.CLI.Features
RedumpPassword = null,
};
Add(_useInput);
Add(_mediaTypeInput);
Add(_deviceInput);
Add(_mountedInput);
Add(_fileInput);
Add(_speedInput);
Add(_customInput);
Add(UseInput);
Add(MediaTypeInput);
Add(DeviceInput);
Add(MountedInput);
Add(FileInput);
Add(SpeedInput);
Add(CustomInput);
}
/// <inheritdoc/>
@@ -99,32 +99,32 @@ namespace MPF.CLI.Features
for (index = 1; index < args.Length; index++)
{
// Use specific program
if (_useInput.ProcessInput(args, ref index))
Options.InternalProgram = _useInput.Value.ToInternalProgram();
if (UseInput.ProcessInput(args, ref index))
Options.InternalProgram = UseInput.Value.ToInternalProgram();
// Set a media type
else if (_mediaTypeInput.ProcessInput(args, ref index))
CommandOptions.MediaType = OptionsLoader.ToMediaType(_mediaTypeInput.Value?.Trim('"'));
else if (MediaTypeInput.ProcessInput(args, ref index))
CommandOptions.MediaType = OptionsLoader.ToMediaType(MediaTypeInput.Value?.Trim('"'));
// Use a device path
else if (_deviceInput.ProcessInput(args, ref index))
CommandOptions.DevicePath = _deviceInput.Value;
else if (DeviceInput.ProcessInput(args, ref index))
CommandOptions.DevicePath = DeviceInput.Value;
// Use a mounted path for physical checks
else if (_mountedInput.ProcessInput(args, ref index))
CommandOptions.MountedPath = _mountedInput.Value;
else if (MountedInput.ProcessInput(args, ref index))
CommandOptions.MountedPath = MountedInput.Value;
// Use a file path
else if (_fileInput.ProcessInput(args, ref index))
CommandOptions.FilePath = _fileInput.Value;
else if (FileInput.ProcessInput(args, ref index))
CommandOptions.FilePath = FileInput.Value;
// Set an override speed
else if (_speedInput.ProcessInput(args, ref index))
CommandOptions.DriveSpeed = _speedInput.Value;
else if (SpeedInput.ProcessInput(args, ref index))
CommandOptions.DriveSpeed = SpeedInput.Value;
// Use a custom parameters
else if (_customInput.ProcessInput(args, ref index))
CommandOptions.CustomParams = _customInput.Value;
else if (CustomInput.ProcessInput(args, ref index))
CommandOptions.CustomParams = CustomInput.Value;
// Default, add to inputs
else

View File

@@ -9,38 +9,12 @@ using MPF.Frontend.Features;
using MPF.Frontend.Tools;
using SabreTools.CommandLine;
using SabreTools.CommandLine.Features;
using SabreTools.CommandLine.Inputs;
using SabreTools.RedumpLib.Data;
namespace MPF.CLI
{
public class Program
{
#region Inputs
private const string _customName = "custom";
private static readonly StringInput _customInput = new(_customName, ["-c", "--custom"], "Custom parameters to use");
private const string _deviceName = "device";
private static readonly StringInput _deviceInput = new(_deviceName, ["-d", "--device"], "Physical drive path (Required if no custom parameters set)");
private const string _fileName = "file";
private static readonly StringInput _fileInput = new(_fileName, ["-f", "--file"], "Output file path (Required if no custom parameters set)");
private const string _mediaTypeName = "media-type";
private static readonly StringInput _mediaTypeInput = new(_mediaTypeName, ["-t", "--mediatype"], "Set media type for dumping (Required for DIC)");
private const string _mountedName = "mounted";
private static readonly StringInput _mountedInput = new(_mountedName, ["-m", "--mounted"], "Mounted filesystem path for additional checks");
private const string _speedName = "speed";
private static readonly Int32Input _speedInput = new(_speedName, ["-s", "--speed"], "Override default dumping speed");
private const string _useName = "use";
private static readonly StringInput _useInput = new(_useName, ["-u", "--use"], "Override configured dumping program name");
#endregion
public static void Main(string[] args)
{
// Load options from the config file
@@ -63,7 +37,8 @@ namespace MPF.CLI
}
// Create the command set
var commandSet = CreateCommands();
var mainFeature = new MainFeature();
var commandSet = CreateCommands(mainFeature);
// If we have no args, show the help and quit
if (args == null || args.Length == 0)
@@ -95,7 +70,6 @@ namespace MPF.CLI
// Default Behavior
default:
var mainFeature = new MainFeature();
mainFeature.ProcessArgs(args, 0);
mainFeature.Execute();
break;
@@ -105,7 +79,7 @@ namespace MPF.CLI
/// <summary>
/// Create the command set for the program
/// </summary>
private static CommandSet CreateCommands()
private static CommandSet CreateCommands(MainFeature mainFeature)
{
List<string> header = [
"MPF.CLI [standalone|system] [options] <path> ...",
@@ -141,13 +115,13 @@ namespace MPF.CLI
commandSet.Add(new InteractiveFeature());
// CLI Options
commandSet.Add(_useInput);
commandSet.Add(_mediaTypeInput);
commandSet.Add(_deviceInput);
commandSet.Add(_mountedInput);
commandSet.Add(_fileInput);
commandSet.Add(_speedInput);
commandSet.Add(_customInput);
commandSet.Add(mainFeature.UseInput);
commandSet.Add(mainFeature.MediaTypeInput);
commandSet.Add(mainFeature.DeviceInput);
commandSet.Add(mainFeature.MountedInput);
commandSet.Add(mainFeature.FileInput);
commandSet.Add(mainFeature.SpeedInput);
commandSet.Add(mainFeature.CustomInput);
return commandSet;
}

View File

@@ -15,59 +15,59 @@ namespace MPF.Check.Features
private static readonly string[] _flags = [];
/// <remarks>Description is unused</remarks>
internal const string _description = "";
private const string _description = "";
#endregion
#region Inputs
internal const string _createIrdName = "create-ird";
private readonly FlagInput _createIrdInput = new(_createIrdName, "--create-ird", "Create IRD from output files (PS3 only)");
private const string _createIrdName = "create-ird";
internal readonly FlagInput CreateIrdInput = new(_createIrdName, "--create-ird", "Create IRD from output files (PS3 only)");
internal const string _deleteName = "delete";
private readonly FlagInput _deleteInput = new(_deleteName, ["-d", "--delete"], "Enable unnecessary file deletion");
private const string _deleteName = "delete";
internal readonly FlagInput DeleteInput = new(_deleteName, ["-d", "--delete"], "Enable unnecessary file deletion");
internal const string _disableArchivesName = "disable-archives";
private readonly FlagInput _disableArchivesInput = new(_disableArchivesName, "--disable-archives", "Disable scanning archives (requires --scan)");
private const string _disableArchivesName = "disable-archives";
internal readonly FlagInput DisableArchivesInput = new(_disableArchivesName, "--disable-archives", "Disable scanning archives (requires --scan)");
internal const string _enableDebugName = "enable-debug";
private readonly FlagInput _enableDebugInput = new(_enableDebugName, "--enable-debug", "Enable debug protection information (requires --scan)");
private const string _enableDebugName = "enable-debug";
internal readonly FlagInput EnableDebugInput = new(_enableDebugName, "--enable-debug", "Enable debug protection information (requires --scan)");
internal const string _hideDriveLettersName = "hide-drive-letters";
private readonly FlagInput _hideDriveLettersInput = new(_hideDriveLettersName, "--hide-drive-letters", "Hide drive letters from scan output (requires --scan)");
private const string _hideDriveLettersName = "hide-drive-letters";
internal readonly FlagInput HideDriveLettersInput = new(_hideDriveLettersName, "--hide-drive-letters", "Hide drive letters from scan output (requires --scan)");
internal const string _includeArtifactsName = "include-artifacts";
private readonly FlagInput _includeArtifactsInput = new(_includeArtifactsName, "--include-artifacts", "Include artifacts in JSON (requires --json)");
private const string _includeArtifactsName = "include-artifacts";
internal readonly FlagInput IncludeArtifactsInput = new(_includeArtifactsName, "--include-artifacts", "Include artifacts in JSON (requires --json)");
internal const string _jsonName = "json";
private readonly FlagInput _jsonInput = new(_jsonName, ["-j", "--json"], "Enable submission JSON output");
private const string _jsonName = "json";
internal readonly FlagInput JsonInput = new(_jsonName, ["-j", "--json"], "Enable submission JSON output");
internal const string _loadSeedName = "load-seed";
private readonly StringInput _loadSeedInput = new(_loadSeedName, "--load-seed", "Load a seed submission JSON for user information");
private const string _loadSeedName = "load-seed";
internal readonly StringInput LoadSeedInput = new(_loadSeedName, "--load-seed", "Load a seed submission JSON for user information");
internal const string _noPlaceholdersName = "no-placeholders";
private readonly FlagInput _noPlaceholdersInput = new(_noPlaceholdersName, "--no-placeholders", "Disable placeholder values in submission info");
private const string _noPlaceholdersName = "no-placeholders";
internal readonly FlagInput NoPlaceholdersInput = new(_noPlaceholdersName, "--no-placeholders", "Disable placeholder values in submission info");
internal const string _noRetrieveName = "no-retrieve";
private readonly FlagInput _noRetrieveInput = new(_noRetrieveName, "--no-retrieve", "Disable retrieving match information from Redump");
private const string _noRetrieveName = "no-retrieve";
internal readonly FlagInput NoRetrieveInput = new(_noRetrieveName, "--no-retrieve", "Disable retrieving match information from Redump");
internal const string _pathName = "path";
private readonly StringInput _pathInput = new(_pathName, ["-p", "--path"], "Physical drive path for additional checks");
private const string _pathName = "path";
internal readonly StringInput PathInput = new(_pathName, ["-p", "--path"], "Physical drive path for additional checks");
internal const string _pullAllName = "pull-all";
private readonly FlagInput _pullAllInput = new(_pullAllName, "--pull-all", "Pull all information from Redump (requires --credentials)");
private const string _pullAllName = "pull-all";
internal readonly FlagInput PullAllInput = new(_pullAllName, "--pull-all", "Pull all information from Redump (requires --credentials)");
internal const string _scanName = "scan";
private readonly FlagInput _scanInput = new(_scanName, ["-s", "--scan"], "Enable copy protection scan (requires --path)");
private const string _scanName = "scan";
internal readonly FlagInput ScanInput = new(_scanName, ["-s", "--scan"], "Enable copy protection scan (requires --path)");
internal const string _suffixName = "suffix";
private readonly FlagInput _suffixInput = new(_suffixName, ["-x", "--suffix"], "Enable adding filename suffix");
private const string _suffixName = "suffix";
internal readonly FlagInput SuffixInput = new(_suffixName, ["-x", "--suffix"], "Enable adding filename suffix");
internal const string _useName = "use";
private readonly StringInput _useInput = new(_useName, ["-u", "--use"], "Override configured dumping program name");
private const string _useName = "use";
internal readonly StringInput UseInput = new(_useName, ["-u", "--use"], "Override configured dumping program name");
internal const string _zipName = "zip";
private readonly FlagInput _zipInput = new(_zipName, ["-z", "--zip"], "Enable log file compression");
private const string _zipName = "zip";
internal readonly FlagInput ZipInput = new(_zipName, ["-z", "--zip"], "Enable log file compression");
#endregion
@@ -102,23 +102,23 @@ namespace MPF.Check.Features
RedumpPassword = null,
};
Add(_useInput);
Add(_loadSeedInput);
Add(_noPlaceholdersInput);
Add(_createIrdInput);
Add(_noRetrieveInput);
Add(UseInput);
Add(LoadSeedInput);
Add(NoPlaceholdersInput);
Add(CreateIrdInput);
Add(NoRetrieveInput);
// TODO: Figure out how to work with the credentials input
Add(_pullAllInput);
Add(_pathInput);
Add(_scanInput);
Add(_disableArchivesInput);
Add(_enableDebugInput);
Add(_hideDriveLettersInput);
Add(_suffixInput);
Add(_jsonInput);
Add(_includeArtifactsInput);
Add(_zipInput);
Add(_deleteInput);
Add(PullAllInput);
Add(PathInput);
Add(ScanInput);
Add(DisableArchivesInput);
Add(EnableDebugInput);
Add(HideDriveLettersInput);
Add(SuffixInput);
Add(JsonInput);
Add(IncludeArtifactsInput);
Add(ZipInput);
Add(DeleteInput);
}
/// <inheritdoc/>
@@ -141,23 +141,23 @@ namespace MPF.Check.Features
for (index = 1; index < args.Length; index++)
{
// Use specific program
if (_useInput.ProcessInput(args, ref index))
Options.InternalProgram = _useInput.Value.ToInternalProgram();
if (UseInput.ProcessInput(args, ref index))
Options.InternalProgram = UseInput.Value.ToInternalProgram();
// Include seed info file
else if (_loadSeedInput.ProcessInput(args, ref index))
CommandOptions.Seed = Builder.CreateFromFile(_loadSeedInput.Value);
else if (LoadSeedInput.ProcessInput(args, ref index))
CommandOptions.Seed = Builder.CreateFromFile(LoadSeedInput.Value);
// Disable placeholder values in submission info
else if (_noPlaceholdersInput.ProcessInput(args, ref index))
else if (NoPlaceholdersInput.ProcessInput(args, ref index))
Options.AddPlaceholders = false;
// Create IRD from output files (PS3 only)
else if (_createIrdInput.ProcessInput(args, ref index))
else if (CreateIrdInput.ProcessInput(args, ref index))
Options.CreateIRDAfterDumping = true;
// Retrieve Redump match information
else if (_noRetrieveInput.ProcessInput(args, ref index))
else if (NoRetrieveInput.ProcessInput(args, ref index))
Options.RetrieveMatchInformation = false;
// Redump login
@@ -175,47 +175,47 @@ namespace MPF.Check.Features
}
// Pull all information (requires Redump login)
else if (_pullAllInput.ProcessInput(args, ref index))
else if (PullAllInput.ProcessInput(args, ref index))
Options.PullAllInformation = true;
// Use a device path for physical checks
else if (_pathInput.ProcessInput(args, ref index))
CommandOptions.DevicePath = _pathInput.Value;
else if (PathInput.ProcessInput(args, ref index))
CommandOptions.DevicePath = PathInput.Value;
// Scan for protection (requires device path)
else if (_scanInput.ProcessInput(args, ref index))
else if (ScanInput.ProcessInput(args, ref index))
scan = true;
// Disable scanning archives (requires --scan)
else if (_scanInput.ProcessInput(args, ref index))
else if (ScanInput.ProcessInput(args, ref index))
enableArchives = false;
// Enable debug protection information (requires --scan)
else if (_enableDebugInput.ProcessInput(args, ref index))
else if (EnableDebugInput.ProcessInput(args, ref index))
enableDebug = true;
// Hide drive letters from scan output (requires --scan)
else if (_hideDriveLettersInput.ProcessInput(args, ref index))
else if (HideDriveLettersInput.ProcessInput(args, ref index))
hideDriveLetters = true;
// Add filename suffix
else if (_suffixInput.ProcessInput(args, ref index))
else if (SuffixInput.ProcessInput(args, ref index))
Options.AddFilenameSuffix = true;
// Output submission JSON
else if (_jsonInput.ProcessInput(args, ref index))
else if (JsonInput.ProcessInput(args, ref index))
Options.OutputSubmissionJSON = true;
// Include JSON artifacts
else if (_includeArtifactsInput.ProcessInput(args, ref index))
else if (IncludeArtifactsInput.ProcessInput(args, ref index))
Options.IncludeArtifacts = true;
// Compress log and extraneous files
else if (_zipInput.ProcessInput(args, ref index))
else if (ZipInput.ProcessInput(args, ref index))
Options.CompressLogFiles = true;
// Delete unnecessary files
else if (_deleteInput.ProcessInput(args, ref index))
else if (DeleteInput.ProcessInput(args, ref index))
Options.DeleteUnnecessaryFiles = true;
// Default, add to inputs

View File

@@ -7,69 +7,17 @@ using MPF.Check.Features;
using MPF.Frontend.Features;
using SabreTools.CommandLine;
using SabreTools.CommandLine.Features;
using SabreTools.CommandLine.Inputs;
using SabreTools.RedumpLib.Data;
namespace MPF.Check
{
public class Program
{
#region Inputs
private const string _createIrdName = "create-ird";
private static readonly FlagInput _createIrdInput = new(_createIrdName, "--create-ird", "Create IRD from output files (PS3 only)");
private const string _deleteName = "delete";
private static readonly FlagInput _deleteInput = new(_deleteName, ["-d", "--delete"], "Enable unnecessary file deletion");
private const string _disableArchivesName = "disable-archives";
private static readonly FlagInput _disableArchivesInput = new(_disableArchivesName, "--disable-archives", "Disable scanning archives (requires --scan)");
private const string _enableDebugName = "enable-debug";
private static readonly FlagInput _enableDebugInput = new(_enableDebugName, "--enable-debug", "Enable debug protection information (requires --scan)");
private const string _hideDriveLettersName = "hide-drive-letters";
private static readonly FlagInput _hideDriveLettersInput = new(_hideDriveLettersName, "--hide-drive-letters", "Hide drive letters from scan output (requires --scan)");
private const string _includeArtifactsName = "include-artifacts";
private static readonly FlagInput _includeArtifactsInput = new(_includeArtifactsName, "--include-artifacts", "Include artifacts in JSON (requires --json)");
private const string _jsonName = "json";
private static readonly FlagInput _jsonInput = new(_jsonName, ["-j", "--json"], "Enable submission JSON output");
private const string _loadSeedName = "load-seed";
private static readonly StringInput _loadSeedInput = new(_loadSeedName, "--load-seed", "Load a seed submission JSON for user information");
private const string _noPlaceholdersName = "no-placeholders";
private static readonly FlagInput _noPlaceholdersInput = new(_noPlaceholdersName, "--no-placeholders", "Disable placeholder values in submission info");
private const string _noRetrieveName = "no-retrieve";
private static readonly FlagInput _noRetrieveInput = new(_noRetrieveName, "--no-retrieve", "Disable retrieving match information from Redump");
private const string _pathName = "path";
private static readonly StringInput _pathInput = new(_pathName, ["-p", "--path"], "Physical drive path for additional checks");
private const string _pullAllName = "pull-all";
private static readonly FlagInput _pullAllInput = new(_pullAllName, "--pull-all", "Pull all information from Redump (requires --credentials)");
private const string _scanName = "scan";
private static readonly FlagInput _scanInput = new(_scanName, ["-s", "--scan"], "Enable copy protection scan (requires --path)");
private const string _suffixName = "suffix";
private static readonly FlagInput _suffixInput = new(_suffixName, ["-x", "--suffix"], "Enable adding filename suffix");
private const string _useName = "use";
private static readonly StringInput _useInput = new(_useName, ["-u", "--use"], "Override configured dumping program name");
private const string _zipName = "zip";
private static readonly FlagInput _zipInput = new(_zipName, ["-z", "--zip"], "Enable log file compression");
#endregion
public static void Main(string[] args)
{
// Create the command set
var commandSet = CreateCommands();
var mainFeature = new MainFeature();
var commandSet = CreateCommands(mainFeature);
// If we have no args, show the help and quit
if (args == null || args.Length == 0)
@@ -101,7 +49,6 @@ namespace MPF.Check
// Default Behavior
default:
var mainFeature = new MainFeature();
mainFeature.ProcessArgs(args, 0);
mainFeature.Execute();
break;
@@ -111,7 +58,7 @@ namespace MPF.Check
/// <summary>
/// Create the command set for the program
/// </summary>
private static CommandSet CreateCommands()
private static CommandSet CreateCommands(MainFeature mainFeature)
{
List<string> header = [
"MPF.CLI [standalone|system] [options] <path> ...",
@@ -137,23 +84,23 @@ namespace MPF.Check
commandSet.Add(new InteractiveFeature());
// Check Options
commandSet.Add(_useInput);
commandSet.Add(_loadSeedInput);
commandSet.Add(_noPlaceholdersInput);
commandSet.Add(_createIrdInput);
commandSet.Add(_noRetrieveInput);
commandSet.Add(mainFeature.UseInput);
commandSet.Add(mainFeature.LoadSeedInput);
commandSet.Add(mainFeature.NoPlaceholdersInput);
commandSet.Add(mainFeature.CreateIrdInput);
commandSet.Add(mainFeature.NoRetrieveInput);
// TODO: Figure out how to work with the credentials input
commandSet.Add(_pullAllInput);
commandSet.Add(_pathInput);
commandSet.Add(_scanInput);
commandSet.Add(_disableArchivesInput);
commandSet.Add(_enableDebugInput);
commandSet.Add(_hideDriveLettersInput);
commandSet.Add(_suffixInput);
commandSet.Add(_jsonInput);
commandSet.Add(_includeArtifactsInput);
commandSet.Add(_zipInput);
commandSet.Add(_deleteInput);
commandSet.Add(mainFeature.PullAllInput);
commandSet.Add(mainFeature.PathInput);
commandSet.Add(mainFeature.ScanInput);
commandSet.Add(mainFeature.DisableArchivesInput);
commandSet.Add(mainFeature.EnableDebugInput);
commandSet.Add(mainFeature.HideDriveLettersInput);
commandSet.Add(mainFeature.SuffixInput);
commandSet.Add(mainFeature.JsonInput);
commandSet.Add(mainFeature.IncludeArtifactsInput);
commandSet.Add(mainFeature.ZipInput);
commandSet.Add(mainFeature.DeleteInput);
return commandSet;
}