From d5b6aee14dff91330b9c550ef14e3175226e40b1 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 2 Feb 2017 16:40:37 -0800 Subject: [PATCH] [SabreTools, Help] Misc improvemets and bug fixes --- SabreTools.Helper/Help/Help.cs | 73 ++++++++++++++++++++++++++++------ SabreTools/SabreTools.cs | 3 ++ 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/SabreTools.Helper/Help/Help.cs b/SabreTools.Helper/Help/Help.cs index fb7614c4..282037ef 100644 --- a/SabreTools.Helper/Help/Help.cs +++ b/SabreTools.Helper/Help/Help.cs @@ -32,8 +32,36 @@ namespace SabreTools.Helper.Help public Feature this[string name] { - get { return _features[name]; } - set { _features[name] = value; } + get + { + if (_features == null) + { + _features = new Dictionary(); + } + + if (!_features.ContainsKey(name)) + { + return null; + } + + return _features[name]; + } + set + { + if (_features == null) + { + _features = new Dictionary(); + } + + if (_features.ContainsKey(name)) + { + _features[name] = value; + } + else + { + _features.Add(name, value); + } + } } /// @@ -59,25 +87,24 @@ namespace SabreTools.Helper.Help #region Instance Methods /// - /// Check if a flag is a top-level (main application) flag + /// Get the feature name for a given flag or short name /// - /// Name of the flag to check - /// True if the feature was found, false otherwise - public bool TopLevelFlag(string flag) + /// Feature name + public string GetFeatureName(string name) { - bool success = false; + string feature = ""; - // Loop through the features and check - foreach (string feature in _features.Keys) + // Loop through the features + foreach (string featureName in _features.Keys) { - if (_features[feature].ValidateInput(flag, exact: true)) + if (_features[featureName].ValidateInput(name, exact: true)) { - success = true; + feature = featureName; break; } } - return success; + return feature; } /// @@ -183,6 +210,28 @@ namespace SabreTools.Helper.Help WriteOutWithPauses(output); } + /// + /// 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; + } + /// /// Write out the help text with pauses, if needed /// diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index e1414a23..296f3cb2 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -258,6 +258,9 @@ namespace SabreTools return; } + // Now get the proper name for the feature + feature = _help.GetFeatureName(feature); + // Determine which switches are enabled (with values if necessary) for (int i = 1; i < args.Length; i++) {