diff --git a/SabreTools.Helper/Help/Help.cs b/SabreTools.Helper/Help/Help.cs index b7a9e01d..fb7614c4 100644 --- a/SabreTools.Helper/Help/Help.cs +++ b/SabreTools.Helper/Help/Help.cs @@ -30,6 +30,12 @@ namespace SabreTools.Helper.Help #region Accessors + public Feature this[string name] + { + get { return _features[name]; } + set { _features[name] = value; } + } + /// /// Add a new feature to the help /// @@ -52,6 +58,28 @@ namespace SabreTools.Helper.Help #region Instance Methods + /// + /// Check if a flag is a top-level (main application) flag + /// + /// Name of the flag to check + /// True if the feature was found, false otherwise + 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; + } + /// /// Output top-level features only /// @@ -108,9 +136,6 @@ namespace SabreTools.Helper.Help // Start building the output list List output = new List(); - // Append the header first - output.AddRange(_header); - // Now try to find the feature that has the name included string realname = null; List startsWith = new List(); @@ -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)); diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index aab289d1..e1414a23 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -166,8 +166,20 @@ namespace SabreTools List sha1 = new List(); List status = new List(); + // 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; }