public void Parse(string[] args) { var first = args.FirstOrDefault() ?? string.Empty; try { var descriptors = CommandDescriptor.GetMemberDescriptors(this.Instance).ToArray(); var parser = new ParseDescriptor(descriptors, args); parser.SetValue(this.Instance); } catch (Exception e) { if (first == string.Empty) { throw new CommandParseException(CommandParseError.Empty, args, true, e); } if (first == this.HelpName) { throw new CommandParseException(CommandParseError.Help, args, true, e); } if (first == this.VersionName) { throw new CommandParseException(CommandParseError.Version, args, true, e); } throw e; } }
internal object Invoke(object instance, string[] args, IEnumerable <CommandMemberDescriptor> descriptors) { var parser = new ParseDescriptor(descriptors, args); var values = new ArrayList(); var nameToDescriptors = descriptors.ToDictionary(item => item.DescriptorName); var parameters = this.MethodInfo.GetParameters(); parser.SetValue(instance); foreach (var item in parameters) { var descriptor = nameToDescriptors[item.Name]; var value = descriptor.GetValueInternal(instance); values.Add(value); } return(this.OnInvoke(instance, values.ToArray())); }
internal static object Create(ICommand command, IEnumerable <CommandMemberDescriptor> members, string[] args, string find) { var parser = new ParseDescriptor(members, args); var properties = new Dictionary <string, object>(); var memberDescriptor = (CommandMemberDescriptor)null; var itemByDescriptor = parser.Items.ToDictionary(item => item.Descriptor); foreach (var item in itemByDescriptor.ToArray()) { var descriptor = item.Key; var parseInfo = item.Value; if (parseInfo.IsParsed == true) { properties.Add(descriptor.DescriptorName, parseInfo.Value); if (descriptor.Usage != CommandPropertyUsage.Variables) { itemByDescriptor.Remove(descriptor); } } } if (args.Any() == true) { var arg = args.First(); foreach (var item in itemByDescriptor) { var descriptor = item.Key; if (arg == descriptor.ShortNamePattern || arg == descriptor.NamePattern) { // int qer = 0; } } } if (find.StartsWith(CommandSettings.Delimiter) == true) { var argList = new List <string>(); foreach (var item in itemByDescriptor) { var descriptor = item.Key; if (descriptor.IsExplicit == false) { continue; } if (descriptor.NamePattern != string.Empty && descriptor.NamePattern.StartsWith(find) == true) { argList.Add(descriptor.NamePattern); } } return(argList.OrderBy(item => item).ToArray()); } else if (find.StartsWith(CommandSettings.ShortDelimiter) == true) { var argList = new List <string>(); foreach (var item in itemByDescriptor) { var descriptor = item.Key; if (descriptor.IsExplicit == false) { continue; } if (descriptor.ShortNamePattern != string.Empty && descriptor.ShortNamePattern.StartsWith(find) == true) { argList.Add(descriptor.ShortNamePattern); } if (descriptor.NamePattern != string.Empty && descriptor.NamePattern.StartsWith(find) == true) { argList.Add(descriptor.NamePattern); } } return(argList.OrderBy(item => item).ToArray()); } else if (itemByDescriptor.Any() == true) { foreach (var item in itemByDescriptor) { var descriptor = item.Key; var parseInfo = item.Value; if (memberDescriptor == null) { memberDescriptor = descriptor; } } return(new CommandCompletionContext(command, memberDescriptor, args.ToArray(), find, properties)); } return(null); }