Exemple #1
0
        void AppendSwitch(CommandLineSwitch @switch, Dictionary <string, CommandLineSwitch> result, int index)
        {
            CommandLineSwitch existingSwitch;

            if (!result.TryGetValue(@switch.Name, out existingSwitch))
            {
                this.CurrentSwitch       = @switch.Clone();
                this.CurrentSwitch.Index = index;
            }
            else
            {
                if (existingSwitch.IsMultiple)
                {
                    this.CurrentSwitch = existingSwitch;
                }
                else
                {
                    this.CurrentSwitch       = @switch.Clone();
                    this.CurrentSwitch.Index = index;
                }
            }

            AppendValueToSwitch(result, this.CurrentSwitch, @switch.Value);
            if ([email protected])
            {
                this.CurrentSwitch = null;
            }
        }
Exemple #2
0
        CommandLineSwitch CreateSwitch(string name, string value, CommandLineConfiguration configuration)
        {
            CommandLineSwitch result = FindSwitch(configuration, name);

            if (result != null)
            {
                result = result.Clone();
            }
            else
            {
                result      = new CommandLineSwitch();
                result.Name = name;
            }
            result.Value = value;
            return(result);
        }
Exemple #3
0
        public Dictionary <string, CommandLineSwitch> Parse(string[] args, CommandLineConfiguration configuration)
        {
            StringComparer comparer = configuration != null && configuration.IsCaseSensitive ? StringComparer.InvariantCulture: StringComparer.InvariantCultureIgnoreCase;
            Dictionary <string, CommandLineSwitch> result = new Dictionary <string, CommandLineSwitch>(comparer);

            if (args == null || args.Length <= 0 || configuration == null /* || configuration.Count <= 0*/)
            {
                return(result);
            }


            this.CurrentSwitch = null;

            int count = args.Length;

            for (int i = 0; i < count; i++)
            {
                CommandLineSwitch @switch = TryParseSwitch(args[i], configuration);
                if (@switch != null)
                {
                    AppendSwitch(@switch, result, i);
                }
                else
                {
                    AppendValue(args[i], result, i);
                }
            }

            if (UnclaimedValues.Count > 0)
            {
                CommandLineSwitch defaultOption = DetectDefaultOptionName(configuration);
                if (defaultOption != null)
                {
                    CommandLineSwitch item = defaultOption.Clone();
                    item.Values = UnclaimedValues;
                    item.Index  = UnclaimedFirstIndex;
                    result[defaultOption.Name] = item;
                    //result[defaultOption.Name] = unclaimedValues;
                }
            }

            return(result);
        }