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");
        }
예제 #2
0
        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);
        }
예제 #3
0
        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>();
        }
예제 #4
0
 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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
예제 #9
0
 public IReadOnlyList <CompletionCandidateValue> GetCandidates(CoconaCompletionCandidatesMetadata metadata, ParsedCommandLine parsedCommandLine)
 {
     throw new NotImplementedException();
 }
예제 #10
0
 public CompletionCandidateResult GetCandidates(CoconaCompletionCandidatesMetadata metadata)
 {
     throw new NotImplementedException();
 }
예제 #11
0
 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;
예제 #12
0
 public CompletionCandidateResult GetCandidates(CoconaCompletionCandidatesMetadata metadata) => _results;