public void HasAttribute() { var argument = new CommandArgumentDescriptor( typeof(int), "test", 0, "", CoconaDefaultValue.None, new Attribute[] { new CompletionCandidatesAttribute(new [] { "Alice", "Karen" }), } ); var metadata = new CoconaCompletionCandidatesMetadata( CompletionCandidateType.Provider, typeof(StaticKeywordsCompletionCandidatesProvider), argument ); var provider = new StaticKeywordsCompletionCandidatesProvider(); var candidates = provider.GetCandidates(metadata); candidates.ResultType.Should().Be(CompletionCandidateResultType.Keywords); candidates.Values.Should().HaveCount(2); candidates.Values[0].Value.Should().Be("Alice"); candidates.Values[1].Value.Should().Be("Karen"); }
public void Argument_EnumValues() { var argument = new CommandArgumentDescriptor( typeof(TestEnum), "test", 0, "", CoconaDefaultValue.None, new Attribute[] { } ); var metadata = new CoconaCompletionCandidatesMetadata( CompletionCandidateType.Provider, typeof(EnumCompletionCandidatesProvider), argument ); var provider = new EnumCompletionCandidatesProvider(); var candidates = provider.GetCandidates(metadata); candidates.ResultType.Should().Be(CompletionCandidateResultType.Keywords); candidates.Values.Should().HaveCount(2); candidates.Values[0].Value.Should().Be("Alice"); candidates.Values[0].Description.Should().Be(string.Empty); candidates.Values[1].Value.Should().Be("Karen"); candidates.Values[1].Description.Should().Be(string.Empty); }
public void OnTheFly() { var serviceProvider = new ServiceCollection().BuildServiceProvider(); var activator = new CoconaInstanceActivator(); var option = new CommandOptionDescriptor( typeof(int), "test", Array.Empty <char>(), "", CoconaDefaultValue.None, string.Empty, CommandOptionFlags.None, new Attribute[] { } ); var factory = new CoconaCompletionCandidatesProviderFactory(serviceProvider, activator); var metadata = new CoconaCompletionCandidatesMetadata( CompletionCandidateType.Provider, typeof(TestOnTheFlyProvider), option ); var provider = factory.CreateOnTheFlyProvider(metadata); provider.Should().BeOfType <TestOnTheFlyProvider>(); }
public CompletionCandidateResult GetCandidates(CoconaCompletionCandidatesMetadata metadata) { return(metadata.CandidateType switch { CompletionCandidateType.Default => CompletionCandidateResult.Default, CompletionCandidateType.Directory => CompletionCandidateResult.Directory, CompletionCandidateType.File => CompletionCandidateResult.File, _ => throw new NotSupportedException(), });
public CompletionCandidateResult GetCandidates(CoconaCompletionCandidatesMetadata metadata) { var attr = metadata.ParameterAttributes.OfType <CompletionCandidatesAttribute>().FirstOrDefault(); if (attr != null) { return(CompletionCandidateResult.Keywords(((ICoconaCompletionCandidatesStaticKeywords)attr).Candidates)); } return(CompletionCandidateResult.Default); }
public void Argument_Default() { var argument = new CommandArgumentDescriptor( typeof(int), "test", 0, "", CoconaDefaultValue.None, new Attribute[] { } ); var metadata = new CoconaCompletionCandidatesMetadata( CompletionCandidateType.Provider, typeof(EnumCompletionCandidatesProvider), argument ); var provider = new EnumCompletionCandidatesProvider(); var candidates = provider.GetCandidates(metadata); candidates.ResultType.Should().Be(CompletionCandidateResultType.Default); }
public void Option_Default() { var option = new CommandOptionDescriptor( typeof(int), "test", Array.Empty <char>(), "", CoconaDefaultValue.None, string.Empty, CommandOptionFlags.None, new Attribute[] { } ); var metadata = new CoconaCompletionCandidatesMetadata( CompletionCandidateType.Provider, typeof(StaticCompletionCandidatesProvider), option ); var provider = new EnumCompletionCandidatesProvider(); var candidates = provider.GetCandidates(metadata); candidates.ResultType.Should().Be(CompletionCandidateResultType.Default); }
public CompletionCandidateResult GetCandidates(CoconaCompletionCandidatesMetadata metadata) => GetCandidates(metadata.ParameterType);
public IReadOnlyList <CompletionCandidateValue> GetCandidates(CoconaCompletionCandidatesMetadata metadata, ParsedCommandLine parsedCommandLine) { throw new NotImplementedException(); }
public CompletionCandidateResult GetCandidates(CoconaCompletionCandidatesMetadata metadata) { throw new NotImplementedException(); }
public IReadOnlyList <CompletionCandidateValue> GetCandidates(CoconaCompletionCandidatesMetadata metadata, ParsedCommandLine parsedCommandLine) => parsedCommandLine.Options.Any(x => x.Option.Name == "group" && string.Equals(x.Value, "trysail", StringComparison.OrdinalIgnoreCase)) ? _resultsTrySail : _resultsSphere;
public CompletionCandidateResult GetCandidates(CoconaCompletionCandidatesMetadata metadata) => _results;