< Summary

Class:GDX.Developer.CommandLineParser
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/CommandLineParser.cs
Covered lines:39
Uncovered lines:0
Coverable lines:39
Total lines:88
Line coverage:100% (39 of 39)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:2
Method coverage:100% (2 of 2)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CommandLineParser()0%110100%
ProcessArguments(...)0%660100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/CommandLineParser.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using GDX.Collections.Generic;
 4
 5namespace GDX.Developer
 6{
 7    /// <summary>
 8    ///     A simplified commandline parser that handles arguments which follow the <c>--FLAG</c> or <c>--KEY=VALUE</c> 
 9    ///     Automatically initialized during normal runtime operations, however can be manually triggered for author tim
 10    ///     use cases as well.
 11    /// </summary>
 12    /// <remarks>
 13    ///     <para>
 14    ///         The prefix and divider are configurable via the <see cref="Config" />, however the always, the <c>FLAG</
 15    ///         and <c>KEY</c> will be Uppercase.
 16    ///     </para>
 17    /// </remarks>
 18    public static class CommandLineParser
 19    {
 20        /// <summary>
 21        ///     The processed arguments found after parsing the arguments
 22        /// </summary>
 223        public static StringKeyDictionary<string> Arguments = new StringKeyDictionary<string>(5);
 24
 25        /// <summary>
 26        ///     The processed flags found in the arguments.
 27        /// </summary>
 228        public static readonly List<string> Flags = new List<string>();
 29
 30        static CommandLineParser()
 231        {
 232            ProcessArguments(Environment.GetCommandLineArgs());
 233        }
 34
 35        /// <summary>
 36        ///     Process an array of arguments into <see cref="Arguments" /> and <see cref="Flags" />.
 37        /// </summary>
 38        /// <param name="argumentArray">An array of arguments to process.</param>
 39        /// <param name="shouldClear">Should the storage containers be cleared.</param>
 40        public static void ProcessArguments(string[] argumentArray, bool shouldClear = true)
 441        {
 442            if (shouldClear)
 443            {
 444                Arguments.Clear();
 445                Flags.Clear();
 446            }
 47
 448            string argumentPrefix = Config.CommandLineParserArgumentPrefix;
 449            int prefixLength = argumentPrefix.Length;
 450            string argumentSplit = Config.CommandLineParserArgumentSplit;
 451            int argumentLength = argumentArray.Length;
 17652            for (int i = 0; i < argumentLength; i++)
 8453            {
 54                // Cache current argument
 8455                string argument = argumentArray[i];
 56
 57                // Has the starter and has an assignment
 8458                if (!argument.StartsWith(argumentPrefix))
 8059                {
 8060                    continue;
 61                }
 62
 463                if (argument.Contains(argumentSplit))
 264                {
 265                    int keyEnd = argument.IndexOf(argumentSplit, StringComparison.Ordinal);
 266                    string key = argument.Substring(prefixLength, keyEnd - prefixLength);
 67
 268                    int valueStart = argument.IndexOf(argumentSplit, StringComparison.Ordinal) + 1;
 269                    int valueEnd = argument.Length;
 270                    string value = argument.Substring(valueStart, valueEnd - valueStart);
 71
 72                    // Value parameter
 273                    Arguments.AddSafe(key.ToUpper(), value);
 274                }
 75                else
 276                {
 277                    string flag = argument.Substring(prefixLength).ToUpper();
 78
 79                    // Flag parameter, ensure they are unique
 280                    if (!Flags.Contains(flag))
 281                    {
 282                        Flags.Add(flag);
 283                    }
 284                }
 485            }
 486        }
 87    }
 88}

Coverage by test methods




Methods/Properties

CommandLineParser()
ProcessArguments(System.String[], System.Boolean)