public void visible_command_has_documentation(ICommandDescriptor command) { if (command.Visible == false) return; command.Description.ShouldNotBeNullOrEmpty(string.Format("command '{0}-{1}' doesn't have a description",command.Verb, command.Noun)); foreach (var commandInput in command.Inputs) commandInput.Value.Description.ShouldNotBeNullOrEmpty(string.Format("command input '{0}' for command '{1}-{2}' doesn't have a description", commandInput.Value.Name,command.Verb, command.Noun)); }
public void ui_command_has_label(ICommandDescriptor command) { var uiDescriptor = command as IUICommandDescriptor; if (uiDescriptor == null) return; uiDescriptor.Label.ShouldNotBeNullOrEmpty(string.Format("UI command '{0}-{1}' doesn't have a label", command.Verb, command.Noun)); }
string CreateParameters(ICommandDescriptor command) { return(PositionalParameters(command) .Concat(NonPositionalParameters(command)) .Select(x => CreateInputDescription(x)) .Join("\r\n\r\n")); }
string CreateUsageLine(ICommandDescriptor command) { var positionedParameters = CreatePositionedParameters(command); var unpositionedParameters = CreateUnpositionedParameters(command); return(new[] { CommandName, positionedParameters, unpositionedParameters }.NotNullOrEmpty().Join(" ")); }
public command_context() { Command = CecilCommandExporter.GetCommandFrom <T>(); Commands = new CommandRepository { Command }; }
public void SendCommand <TCommand, TRequest, TResponse>( ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, TRequest request, EntityId entityId, CommandCallback <TResponse> callback, TimeSpan?timeout = null, CommandDelivery commandDelivery = CommandDelivery.RoundTrip) where TCommand : ICommandMetaclass, new() { SendCommandInternal(null, SkipAuthorityCheck, commandDescriptor, request, entityId, callback, timeout, commandDelivery); }
string CreateParameters(ICommandDescriptor command) { return PositionalParameters(command) .Concat(NonPositionalParameters(command)) .Select(x => CreateInputDescription(x)) .Join("\r\n\r\n"); }
public CommandDescriptionOutput(ICommandDescriptor command) : base(null) { Command = command; CommandName = string.Format("{0}-{1}", command.Verb, command.Noun); Description = command.Description; UsageLine = CreateUsageLine(command); Parameters = CreateParameters(command); }
private ICommandDescriptor ThrowIfNullDescriptor(ICommandDescriptor descriptor) { if (descriptor == null) { throw new ArgumentException("A command descriptor is required for this registration."); } return(descriptor); }
public CommandLineHelpEventArgs( ICommandDescriptor commandInfo, IEnumerable <ICommandDescriptor> subCommandInfo, IDictionary <string, string> syntaxInfo) { CommandInfo = commandInfo; SubCommandInfo = subCommandInfo; SyntaxInfo = syntaxInfo; }
public void ui_command_has_label(ICommandDescriptor command) { var uiDescriptor = command as IUICommandDescriptor; if (uiDescriptor == null) { return; } uiDescriptor.Label.ShouldNotBeNullOrEmpty(string.Format("UI command '{0}-{1}' doesn't have a label", command.Verb, command.Noun)); }
IEnumerable <ICommandInputDescriptor> NonPositionalParameters(ICommandDescriptor command) { return(command.Inputs .Select(x => x.Value) .Where(x => x.Position == null && x.IsRequired) .OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase) .Concat( command.Inputs.Select(x => x.Value) .Where(x => x.Position == null && x.IsRequired == false) .OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase) )); }
public void visible_command_has_documentation(ICommandDescriptor command) { if (command.Visible == false) { return; } command.Description.ShouldNotBeNullOrEmpty(string.Format("command '{0}-{1}' doesn't have a description", command.Verb, command.Noun)); foreach (var commandInput in command.Inputs) { commandInput.Value.Description.ShouldNotBeNullOrEmpty(string.Format("command input '{0}' for command '{1}-{2}' doesn't have a description", commandInput.Value.Name, command.Verb, command.Noun)); } }
static IEnumerable<ICommandInputDescriptor> NonPositionalParameters(ICommandDescriptor command) { return command.Inputs .Select(x => x.Value) .Where(x => x.Position == null && x.IsRequired) .OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase) .Concat( command.Inputs.Select(x => x.Value) .Where(x => x.Position == null && x.IsRequired == false) .OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase) ); }
private ICommandDescriptor GetCommandDescriptor <TDescriptorContainer>( Func <TDescriptorContainer, ICommandDescriptor> getDescriptorFunc) { ICommandDescriptor descriptor = null; if (getDescriptorFunc != null) { var descriptorContainer = commandServiceProvider.Resolve <TDescriptorContainer>(); descriptor = getDescriptorFunc(descriptorContainer); } return(descriptor); }
private void SendCommandInternal <TCommand, TRequest, TResponse>(IComponentWriter writer, bool requireAuthority, ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, TRequest request, EntityId entityId, CommandCallback <TResponse> callback, TimeSpan?timeout, CommandDelivery commandDelivery) where TCommand : ICommandMetaclass, new() { Action sendAction = () => { var rawRequest = commandDescriptor.CreateRequest(request); Func <ICommandResponse <TCommand>, TResponse> extractResponse = rawResponse => ExtractResponse(commandDescriptor, rawResponse); var requestId = componentCommander.SendCommandInternal(entityId, rawRequest, extractResponse, callback, timeout, commandDelivery); TrackRequest(writer, requestId); }; SendGenericCommand(writer, requireAuthority, callback, sendAction); }
public void Add(ICommandDescriptor commandDescriptor) { if (commandDescriptor == null) { throw new ArgumentNullException("commandDescriptor"); } if (commandDescriptor.Noun != null && !_nouns.Contains(commandDescriptor.Noun)) { _nouns.Add(commandDescriptor.Noun); } if (commandDescriptor.Verb != null && !_commandVerbs.Contains(commandDescriptor.Verb)) { _commandVerbs.Add(commandDescriptor.Verb); } _commands.Add(commandDescriptor); }
protected void when_executing(string line) { this.Result = Handler.Execute(ref line); ResultingLine = line; }
public CommandListResult(ICommandDescriptor repository) { _command = repository; }
public PluginB_v2() { Descriptor = new CommandDescriptor("pluginB_dependency", "command B"); }
public IEnumerable <ICommandOutput> Run(ICommandDescriptor command, string line) { var commandInstance = LastCommand = command.Create(); var parsedInput = new InputParser().Parse(line).ToList(); var unassignedInputs = new List <Input>(); var assignedInputs = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var input in parsedInput) { var inputName = input.Name; if (!string.IsNullOrEmpty(inputName)) { ICommandInputDescriptor assigner; if (!command.Inputs.TryGetValue(inputName, out assigner)) { var potentialInputs = inputName.SelectHumps(command.Inputs.Keys).ToList(); if (potentialInputs.Count == 1) { inputName = potentialInputs.Single(); } else if (potentialInputs.Count > 1) { yield return(new AmbiguousInputName(inputName, potentialInputs)); yield break; } } if (assignedInputs.Contains(inputName)) { yield return(new CommandInputTooManyTimes(inputName)); yield break; } bool canIgnore = OptionalInputs.ContainsNoCase(inputName); if (!command.Inputs.TryGetValue(inputName, out assigner) && !canIgnore) { yield return(new UnknownCommandInput(inputName)); yield break; } if (assigner != null && !AssignValue(input, commandInstance, assigner)) { yield return(new InputParsingError(inputName, GetLinearValue(input))); yield break; } assignedInputs.Add(inputName); } else { unassignedInputs.Add(input); } } if (unassignedInputs.Count > 0) { foreach (var positioned in command.Inputs .Where(x => x.Value.Position != null && !assignedInputs.Contains(x.Key)) .Select(x => x.Value) .OrderBy(x => x.Position)) { if (unassignedInputs.Count == 0) { break; } if (!AssignValue(unassignedInputs[0], commandInstance, positioned)) { yield return(new InputParsingError(positioned.Name, GetLinearValue(unassignedInputs[0]))); yield break; } assignedInputs.Add(positioned.Name); unassignedInputs.RemoveAt(0); } } var missingInputs = command.Inputs.Where(x => x.Value.IsRequired && !assignedInputs.Contains(x.Key)).Select(x => x.Value); if (missingInputs.Any()) { yield return(new MissingInput(missingInputs)); yield break; } foreach (var output in commandInstance.Execute()) { yield return(output); } }
public CommandExportItem(string path, IPackage package, ICommandDescriptor descriptor) { Path = path; Package = package; Descriptor = descriptor; }
ICommandInputDescriptor FindCommandInputDescriptor(ICommandDescriptor command, string name) { ICommandInputDescriptor descriptor; // Try to find by full name match first. if (command.Inputs.TryGetValue(name, out descriptor)) { return descriptor; } var potentialInputs = (from input in command.Inputs where name.MatchesHumps(input.Key) select input.Value).ToList(); if (potentialInputs.Count > 1) throw new AmbiguousInputNameException(name, potentialInputs.Select(x=>x.Name).ToArray()); return potentialInputs.SingleOrDefault(); }
public static TResponse ExtractResponse <TCommand, TRequest, TResponse> (ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, ICommandResponse <TCommand> rawResponse) where TCommand : ICommandMetaclass, new() { return(commandDescriptor.ExtractResponse(rawResponse)); }
public bool Remove(ICommandDescriptor item) { return(_commands.Remove(item)); }
/// <inheritdoc /> public ICommandResponseHandler <TResponse> SendCommand <TCommand, TRequest, TResponse>(IComponentWriter writer, ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, TRequest request, EntityId entityId, TimeSpan?timeout, CommandDelivery commandDelivery = CommandDelivery.RoundTrip) where TCommand : ICommandMetaclass, new() { return(CommandResponseHandler <TResponse> .Wrap(callback => SendCommandInternal(writer, PerformAuthorityCheck, commandDescriptor, request, entityId, callback, timeout, commandDelivery))); }
public PluginB_v1() { Descriptor = new CommandDescriptor("pluginB_stright", "command B"); }
public VerbSlice(ICommandDescriptor commandDescriptor) { Verb = commandDescriptor.Verb; this.Command = commandDescriptor; }
public cecil_command() { CommandDescriptor = CecilCommandExporter.GetCommandFrom <T>(); }
public IEnumerable<ICommandOutput> Run(ICommandDescriptor command, string line) { var commandInstance = LastCommand = command.Create(); var parsedInput = InputParser.Parse(line).ToList(); var unassignedInputs = new List<Input>(); var assignedInputs = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (var input in parsedInput) { var inputName = input.Name; if (!string.IsNullOrEmpty(inputName)) { ICommandInputDescriptor assigner; if (!command.Inputs.TryGetValue(inputName, out assigner)) { var potentialInputs = inputName.SelectHumps(command.Inputs.Keys).ToList(); if (potentialInputs.Count == 1) inputName = potentialInputs.Single(); else if (potentialInputs.Count > 1) { yield return new AmbiguousInputName(inputName, potentialInputs); yield break; } } if (assignedInputs.Contains(inputName)) { yield return new CommandInputTooManyTimes(inputName); yield break; } bool canIgnore = OptionalInputs.ContainsNoCase(inputName); if (!command.Inputs.TryGetValue(inputName, out assigner) && !canIgnore) { yield return new UnknownCommandInput(inputName); yield break; } if (assigner != null && !AssignValue(input, commandInstance, assigner)) { yield return new InputParsingError(inputName, GetLinearValue(input)); yield break; } assignedInputs.Add(inputName); } else { unassignedInputs.Add(input); } } if (unassignedInputs.Count > 0) { foreach (var positioned in command.Inputs .Where(x => x.Value.Position != null && !assignedInputs.Contains(x.Key)) .Select(x => x.Value) .OrderBy(x => x.Position)) { if (unassignedInputs.Count == 0) break; if (!AssignValue(unassignedInputs[0], commandInstance, positioned)) { yield return new InputParsingError(positioned.Name, GetLinearValue(unassignedInputs[0])); yield break; } assignedInputs.Add(positioned.Name); unassignedInputs.RemoveAt(0); } } var missingInputs = command.Inputs.Where(x => x.Value.IsRequired && !assignedInputs.Contains(x.Key)).Select(x => x.Value); if (missingInputs.Any()) { yield return new MissingInput(missingInputs); yield break; } foreach (var output in commandInstance.Execute()) yield return output; }
string CreateUnpositionedParameters(ICommandDescriptor command) { return NonPositionalParameters(command) .Select(CreateUnpositionedParameter) .Join(" "); }
public CommandsSniffer() : base(new SortedDictionary <ReadOnlyMemory <char>, ICommandArgumentCountDictionary>(new MemoryStringComparer()), typeof(ICommandHandler <>)) { NotFoundCommand = new CommandDescriptor <Application, NotFoundCommandArgument>(); BadArgumentCountCommand = new CommandDescriptor <Application, BadArgumentCountCommandArgument>(); }
IOrderedEnumerable<ICommandInputDescriptor> PositionalParameters(ICommandDescriptor command) { return command.Inputs.Select(x=>x.Value) .Where(x => x.Position != null) .OrderBy(x => x.Position); }
IEnumerable <ICommandOutput> CommandDescription(ICommandDescriptor matchingCommand) { yield return(new CommandDescriptionOutput(matchingCommand)); }
public UniqueNameAndOneLongArgumentCommandArgumentCountDictionary(ICommandDescriptor descriptor) : base(descriptor) { }
IEnumerable<ICommandOutput> CommandDescription(ICommandDescriptor matchingCommand) { yield return new CommandDescriptionOutput(matchingCommand); }
// Helper for one argument and one command actions. static InvokersParametersPair JustOneArgument(ICommandDescriptor command, object o) => JustOneArgument(command.AsSingleEnumerable(), o);
string CreateUsageLine(ICommandDescriptor command) { var positionedParameters = CreatePositionedParameters(command); var unpositionedParameters = CreateUnpositionedParameters(command); return new[] { CommandName, positionedParameters, unpositionedParameters }.NotNullOrEmpty().Join(" "); }
string CreatePositionedParameters(ICommandDescriptor command) { return(PositionalParameters(command) .Select(CreatePositionedParameter) .Join(" ")); }
IOrderedEnumerable <ICommandInputDescriptor> PositionalParameters(ICommandDescriptor command) { return(command.Inputs.Select(x => x.Value) .Where(x => x.Position != null) .OrderBy(x => x.Position)); }