Ejemplo n.º 1
0
        /// <summary>
        /// Gets the word in a switch from the current argument or parses a file.
        /// For example -foo, /foo, or --foo would return 'foo'.
        /// </summary>
        /// <param name="args">
        /// The command line parameters to be processed.
        /// </param>
        /// <param name="argIndex">
        /// The index in args to the argument to process.
        /// </param>
        /// <param name="parser">
        /// Used to parse files in the args.  If not supplied, Files will not be parsed.
        /// </param>
        /// <param name="noexitSeen">
        /// Used during parsing files.
        /// </param>
        /// <returns>
        /// Returns a Tuple:
        /// The first value is a String called SwitchKey with the word in a switch from the current argument or null.
        /// The second value is a bool called ShouldBreak, indicating if the parsing look should break.
        /// </returns>
        private static (string SwitchKey, bool ShouldBreak) GetSwitchKey(string[] args, ref int argIndex, CommandLineParameterParser parser, ref bool noexitSeen)
        {
            string switchKey = args[argIndex].Trim().ToLowerInvariant();

            if (string.IsNullOrEmpty(switchKey))
            {
                return(SwitchKey : null, ShouldBreak : false);
            }

            if (!CharExtensions.IsDash(switchKey[0]) && switchKey[0] != '/')
            {
                // then its a file
                if (parser != null)
                {
                    --argIndex;
                    parser.ParseFile(args, ref argIndex, noexitSeen);
                }

                return(SwitchKey : null, ShouldBreak : true);
            }

            // chop off the first character so that we're agnostic wrt specifying / or -
            // in front of the switch name.
            switchKey = switchKey.Substring(1);

            // chop off the second dash so we're agnostic wrt specifying - or --
            if (!string.IsNullOrEmpty(switchKey) && CharExtensions.IsDash(switchKey[0]))
            {
                switchKey = switchKey.Substring(1);
            }

            return(SwitchKey : switchKey, ShouldBreak : false);
        }