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
|
||||
|
||||
public Feature this[string name]
|
||||
{
|
||||
get { return _features[name]; }
|
||||
set { _features[name] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new feature to the help
|
||||
/// </summary>
|
||||
@@ -52,6 +58,28 @@ namespace SabreTools.Helper.Help
|
||||
|
||||
#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>
|
||||
/// Output top-level features only
|
||||
/// </summary>
|
||||
@@ -108,9 +136,6 @@ namespace SabreTools.Helper.Help
|
||||
// Start building the output list
|
||||
List<string> output = new List<string>();
|
||||
|
||||
// Append the header first
|
||||
output.AddRange(_header);
|
||||
|
||||
// Now try to find the feature that has the name included
|
||||
string realname = null;
|
||||
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
|
||||
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)
|
||||
{
|
||||
output.AddRange(_features[possible].Output(pre: 2, midpoint: 25));
|
||||
|
||||
@@ -166,8 +166,20 @@ namespace SabreTools
|
||||
List<string> sha1 = 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
|
||||
switch (args[0])
|
||||
switch (feature)
|
||||
{
|
||||
case "-?":
|
||||
case "-h":
|
||||
@@ -226,6 +238,10 @@ namespace SabreTools
|
||||
case "--type-split":
|
||||
splitByType = true;
|
||||
break;
|
||||
case "-ud":
|
||||
case "--update":
|
||||
update = true;
|
||||
break;
|
||||
case "-ve":
|
||||
case "--verify":
|
||||
verify = true;
|
||||
@@ -237,13 +253,23 @@ namespace SabreTools
|
||||
|
||||
// If we don't have a valid flag, feed it through the help system
|
||||
default:
|
||||
_help.OutputIndividualFeature(args[0]);
|
||||
_help.OutputIndividualFeature(feature);
|
||||
_logger.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine which switches are enabled (with values if necessary)
|
||||
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])
|
||||
{
|
||||
// User flags
|
||||
@@ -515,10 +541,6 @@ namespace SabreTools
|
||||
case "--tzip":
|
||||
outputFormat = OutputFormat.TorrentZip;
|
||||
break;
|
||||
case "-ud":
|
||||
case "--update":
|
||||
update = true;
|
||||
break;
|
||||
case "-upd":
|
||||
case "--update-dat":
|
||||
updateDat = true;
|
||||
@@ -1014,6 +1036,7 @@ namespace SabreTools
|
||||
if (!(datFromDir | extract | restore | sort | sortDepot | splitByExt | splitByHash | splitByLevel | splitByType | stats | update | verify | verifyDepot))
|
||||
{
|
||||
_logger.Error("At least one feature switch must be enabled");
|
||||
_help.OutputGenericHelp();
|
||||
_logger.Close();
|
||||
return;
|
||||
}
|
||||
@@ -1022,6 +1045,7 @@ namespace SabreTools
|
||||
if (!(datFromDir ^ extract ^ restore ^ sort ^ sortDepot ^ splitByExt ^ splitByHash ^ splitByLevel ^ splitByType ^ stats ^ update ^ verify))
|
||||
{
|
||||
_logger.Error("Only one feature switch is allowed at a time");
|
||||
_help.OutputGenericHelp();
|
||||
_logger.Close();
|
||||
return;
|
||||
}
|
||||
@@ -1031,6 +1055,7 @@ namespace SabreTools
|
||||
&& (datFromDir || extract || restore || splitByExt || splitByHash || splitByLevel || splitByType || stats || update || verify || verifyDepot))
|
||||
{
|
||||
_logger.Error("This feature requires at least one input");
|
||||
_help.OutputIndividualFeature(feature);
|
||||
_logger.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user