mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools, Help] Minor improvements
This commit is contained in:
@@ -30,6 +30,12 @@ namespace SabreTools.Helper.Help
|
|||||||
|
|
||||||
#region Accessors
|
#region Accessors
|
||||||
|
|
||||||
|
public Feature this[string name]
|
||||||
|
{
|
||||||
|
get { return _features[name]; }
|
||||||
|
set { _features[name] = value; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a new feature to the help
|
/// Add a new feature to the help
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -52,6 +58,28 @@ namespace SabreTools.Helper.Help
|
|||||||
|
|
||||||
#region Instance Methods
|
#region Instance Methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if a flag is a top-level (main application) flag
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="flag">Name of the flag to check</param>
|
||||||
|
/// <returns>True if the feature was found, false otherwise</returns>
|
||||||
|
public bool TopLevelFlag(string flag)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
// Loop through the features and check
|
||||||
|
foreach (string feature in _features.Keys)
|
||||||
|
{
|
||||||
|
if (_features[feature].ValidateInput(flag, exact: true))
|
||||||
|
{
|
||||||
|
success = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Output top-level features only
|
/// Output top-level features only
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -108,9 +136,6 @@ namespace SabreTools.Helper.Help
|
|||||||
// Start building the output list
|
// Start building the output list
|
||||||
List<string> output = new List<string>();
|
List<string> output = new List<string>();
|
||||||
|
|
||||||
// Append the header first
|
|
||||||
output.AddRange(_header);
|
|
||||||
|
|
||||||
// Now try to find the feature that has the name included
|
// Now try to find the feature that has the name included
|
||||||
string realname = null;
|
string realname = null;
|
||||||
List<string> startsWith = new List<string>();
|
List<string> startsWith = new List<string>();
|
||||||
@@ -147,7 +172,7 @@ namespace SabreTools.Helper.Help
|
|||||||
// If no name was found but we have possible matches, show them
|
// If no name was found but we have possible matches, show them
|
||||||
else if (startsWith.Count > 0)
|
else if (startsWith.Count > 0)
|
||||||
{
|
{
|
||||||
output.Add(featurename + " not found. Did you mean:");
|
output.Add("\"" + featurename + "\" not found. Did you mean:");
|
||||||
foreach (string possible in startsWith)
|
foreach (string possible in startsWith)
|
||||||
{
|
{
|
||||||
output.AddRange(_features[possible].Output(pre: 2, midpoint: 25));
|
output.AddRange(_features[possible].Output(pre: 2, midpoint: 25));
|
||||||
|
|||||||
@@ -166,8 +166,20 @@ namespace SabreTools
|
|||||||
List<string> sha1 = new List<string>();
|
List<string> sha1 = new List<string>();
|
||||||
List<string> status = new List<string>();
|
List<string> status = new List<string>();
|
||||||
|
|
||||||
|
// Get the first argument as a feature flag
|
||||||
|
string feature = args[0];
|
||||||
|
|
||||||
|
// Verify that the flag is valid
|
||||||
|
if (!_help.TopLevelFlag(feature))
|
||||||
|
{
|
||||||
|
_logger.User("\"" + feature + "\" is not valid feature flag");
|
||||||
|
_help.OutputIndividualFeature(feature);
|
||||||
|
_logger.Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check the first argument for being a feature flag
|
// Check the first argument for being a feature flag
|
||||||
switch (args[0])
|
switch (feature)
|
||||||
{
|
{
|
||||||
case "-?":
|
case "-?":
|
||||||
case "-h":
|
case "-h":
|
||||||
@@ -226,6 +238,10 @@ namespace SabreTools
|
|||||||
case "--type-split":
|
case "--type-split":
|
||||||
splitByType = true;
|
splitByType = true;
|
||||||
break;
|
break;
|
||||||
|
case "-ud":
|
||||||
|
case "--update":
|
||||||
|
update = true;
|
||||||
|
break;
|
||||||
case "-ve":
|
case "-ve":
|
||||||
case "--verify":
|
case "--verify":
|
||||||
verify = true;
|
verify = true;
|
||||||
@@ -237,13 +253,23 @@ namespace SabreTools
|
|||||||
|
|
||||||
// If we don't have a valid flag, feed it through the help system
|
// If we don't have a valid flag, feed it through the help system
|
||||||
default:
|
default:
|
||||||
_help.OutputIndividualFeature(args[0]);
|
_help.OutputIndividualFeature(feature);
|
||||||
|
_logger.Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine which switches are enabled (with values if necessary)
|
// Determine which switches are enabled (with values if necessary)
|
||||||
for (int i = 1; i < args.Length; i++)
|
for (int i = 1; i < args.Length; i++)
|
||||||
{
|
{
|
||||||
|
// Verify that the current flag is proper for the feature
|
||||||
|
if (!_help[feature].ValidateInput(args[i]))
|
||||||
|
{
|
||||||
|
_logger.Error("Invalid input detected: " + args[i]);
|
||||||
|
_help.OutputIndividualFeature(feature);
|
||||||
|
_logger.Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (args[i])
|
switch (args[i])
|
||||||
{
|
{
|
||||||
// User flags
|
// User flags
|
||||||
@@ -515,10 +541,6 @@ namespace SabreTools
|
|||||||
case "--tzip":
|
case "--tzip":
|
||||||
outputFormat = OutputFormat.TorrentZip;
|
outputFormat = OutputFormat.TorrentZip;
|
||||||
break;
|
break;
|
||||||
case "-ud":
|
|
||||||
case "--update":
|
|
||||||
update = true;
|
|
||||||
break;
|
|
||||||
case "-upd":
|
case "-upd":
|
||||||
case "--update-dat":
|
case "--update-dat":
|
||||||
updateDat = true;
|
updateDat = true;
|
||||||
@@ -1014,6 +1036,7 @@ namespace SabreTools
|
|||||||
if (!(datFromDir | extract | restore | sort | sortDepot | splitByExt | splitByHash | splitByLevel | splitByType | stats | update | verify | verifyDepot))
|
if (!(datFromDir | extract | restore | sort | sortDepot | splitByExt | splitByHash | splitByLevel | splitByType | stats | update | verify | verifyDepot))
|
||||||
{
|
{
|
||||||
_logger.Error("At least one feature switch must be enabled");
|
_logger.Error("At least one feature switch must be enabled");
|
||||||
|
_help.OutputGenericHelp();
|
||||||
_logger.Close();
|
_logger.Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1022,6 +1045,7 @@ namespace SabreTools
|
|||||||
if (!(datFromDir ^ extract ^ restore ^ sort ^ sortDepot ^ splitByExt ^ splitByHash ^ splitByLevel ^ splitByType ^ stats ^ update ^ verify))
|
if (!(datFromDir ^ extract ^ restore ^ sort ^ sortDepot ^ splitByExt ^ splitByHash ^ splitByLevel ^ splitByType ^ stats ^ update ^ verify))
|
||||||
{
|
{
|
||||||
_logger.Error("Only one feature switch is allowed at a time");
|
_logger.Error("Only one feature switch is allowed at a time");
|
||||||
|
_help.OutputGenericHelp();
|
||||||
_logger.Close();
|
_logger.Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1031,6 +1055,7 @@ namespace SabreTools
|
|||||||
&& (datFromDir || extract || restore || splitByExt || splitByHash || splitByLevel || splitByType || stats || update || verify || verifyDepot))
|
&& (datFromDir || extract || restore || splitByExt || splitByHash || splitByLevel || splitByType || stats || update || verify || verifyDepot))
|
||||||
{
|
{
|
||||||
_logger.Error("This feature requires at least one input");
|
_logger.Error("This feature requires at least one input");
|
||||||
|
_help.OutputIndividualFeature(feature);
|
||||||
_logger.Close();
|
_logger.Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user