private string BuildDocString(ApiCommand command) { var docString = new StringBuilder(command.Name).Append(":\t"); void DocParam(ApiParameter parameter) { if (parameter != null) { docString.Append("/").Append(parameter.Optional ? '[' : '<').Append(parameter.Name); if (!string.IsNullOrWhiteSpace(parameter.Type)) { docString.Append(':').Append(parameter.Type); } docString.Append(parameter.Optional ? ']' : '>'); } } if (command.Parameters != null) { docString.Append("(Usage: \""); DocParam(command.Parameters.FirstOrDefault(p => p.IsPrepend)); docString.Append('/').Append(command.Name); foreach (var parameter in command.Parameters.Where(p => !p.IsPrepend)) { DocParam(parameter); } docString.Append("\")\t"); } docString.Append(command.Description ?? "No description provided"); return(docString.ToString()); }
public PublicApi(IEmulatorServiceProvider serviceProvider) { apiProviders = ReflectiveEnumerator.GetEnumerableOfType <ApiProvider>(); Documentation = new ApiCommand("Help", (args, domain) => string.Join("\n", Commands.Select(c => BuildDocString(c.Value))), new List <ApiParameter>(), "Lists available commands (This message)"); Commands["Help"] = Documentation; foreach (var provider in apiProviders) { foreach (var command in provider.Commands) { Commands.Add(command.Name, command); } } Update(serviceProvider); }