static ArgumentProcessor()
        {
            // Initialize the set of valid descriptors.
            // To add a new argument, just add it to the list.
            Descriptors = new List <ArgumentDescriptor>
            {
                new ArgumentDescriptor(
                    id: KeywordIds.ProjectKey, prefixes:  CommandLineFlagPrefix.GetPrefixedFlags("key:", "k:"), required: true, allowMultiple: false,
                    description: Resources.CmdLine_ArgDescription_ProjectKey),

                new ArgumentDescriptor(
                    id: KeywordIds.ProjectName, prefixes: CommandLineFlagPrefix.GetPrefixedFlags("name:", "n:"), required: false, allowMultiple: false,
                    description: Resources.CmdLine_ArgDescription_ProjectName),

                new ArgumentDescriptor(
                    id: KeywordIds.ProjectVersion, prefixes: CommandLineFlagPrefix.GetPrefixedFlags("version:", "v:"), required: false,
                    allowMultiple: false, description: Resources.CmdLine_ArgDescription_ProjectVersion),

                new ArgumentDescriptor(
                    id: KeywordIds.Organization, prefixes: CommandLineFlagPrefix.GetPrefixedFlags("organization:", "o:"), required: false,
                    allowMultiple: false, description: Resources.CmdLine_ArgDescription_Organization),

                new ArgumentDescriptor(
                    id: KeywordIds.InstallLoaderTargets, prefixes: CommandLineFlagPrefix.GetPrefixedFlags("install:"), required: false,
                    allowMultiple: false, description: Resources.CmdLine_ArgDescription_InstallTargets),

                FilePropertyProvider.Descriptor,
                CmdLineArgPropertyProvider.Descriptor
            };

            Debug.Assert(Descriptors.All(d => d.Prefixes != null && d.Prefixes.Any()), "All descriptors must provide at least one prefix");
            Debug.Assert(Descriptors.Select(d => d.Id).Distinct().Count() == Descriptors.Count, "All descriptors must have a unique id");
        }
        public void Parser_ShouldReturnPrefixedFlags()
        {
            //arrange
            var args = new string[] { "a:", "alias:" };

            var expectedResult = new string[] { "-a:", "/a:", "-alias:", "/alias:" };

            //act
            var argsPrefixed = CommandLineFlagPrefix.GetPrefixedFlags(args);

            //assert
            CollectionAssert.AreEqual(argsPrefixed, expectedResult);
        }
Beispiel #3
0
        public static bool IsHelp(string[] commandLineArgs)
        {
            var helpPrefixes = CommandLineFlagPrefix.GetPrefixedFlags("h", "?");

            foreach (var helpPrefix in helpPrefixes)
            {
                if (commandLineArgs.Contains(helpPrefix))
                {
                    return(true);
                }
            }

            return(false);
        }