Exemple #1
0
        public string[] GetDescriptionColumns(OptionDescriptor descr)
        {
            var shortNameColumn = new StringBuilder();

            if (null != descr.ShortNames && descr.ShortNames.Length > 0)
            {
                shortNameColumn.Append('-').Append(descr.ShortNames[0]);
                for (int i = 1; i < descr.ShortNames.Length; i++)
                {
                    shortNameColumn.Append("|").Append(descr.ShortNames[i]);
                }
            }

            var longNameColumn = new StringBuilder();

            if (null != descr.LongNames && descr.LongNames.Length > 0)
            {
                longNameColumn.Append("--").Append(descr.LongNames[0]);
                for (int i = 1; i < descr.LongNames.Length; i++)
                {
                    longNameColumn.Append("|").Append(descr.LongNames[i]);
                }
            }

            var shortNameColumnString = shortNameColumn.ToString();
            var longNameColumnString  = longNameColumn.ToString();
            var shortDescription      = descr.ShortDescription ?? string.Empty;

            var columns = new[] { shortNameColumnString, longNameColumnString, shortDescription };

            return(columns);
        }
Exemple #2
0
 public static void AddAliases(this OptionDescriptor option, IEnumerable <string> aliases)
 {
     foreach (var alias in aliases)
     {
         option.Aliases.Add(alias);
     }
 }
Exemple #3
0
        internal static OptionDescriptor CreateOptionDescriptor(string name, Type type)
        {
            var option = new OptionDescriptor(null, name, RawInfo.DummyProperty);

            option.Arguments.Add(new ArgumentDescriptor(new ArgTypeInfoRoslyn(type), null, name, RawInfo.DummyProperty));
            return(option);
        }
Exemple #4
0
        internal static CliDescriptor WrapInCliDescriptor(this OptionDescriptor optionDescriptor)
        {
            var clidDescriptor = new CliDescriptor()
            {
                CommandDescriptor = new CommandDescriptor(null, "MyClass", RawInfo.DummyClass)
            };

            clidDescriptor.CommandDescriptor.Options.Add(optionDescriptor);
            return(clidDescriptor);
        }
        public SingleOptionTestCommand(string testName,
                                       string originalName,
                                       string commandLineName,
                                       string typeStringRepresentation,
                                       string?description,
                                       DefaultValueDescriptor?defaultValue)
            : base(testName)
        {
            string SourceCode = $@"
                var command = new Command(""my-class"", """");
                command.Options.Add(GetOption<{typeStringRepresentation}>(""{commandLineName}"", ""{description}"", {defaultValue.CodeRepresentation}));
                return command;";

            GeneratedNamespace       = "StarFruit2.Tests.TestSampleData" + testName;
            GeneratedSourceClassName = testName + "CommandSource";

            var commandDescriptor = CommandDescriptor;

            var option = new OptionDescriptor(commandDescriptor, originalName, RawInfo.DummyProperty)
            {
                Name        = originalName,
                CliName     = commandLineName,
                Description = description,
            };

            option.Arguments.Add(new ArgumentDescriptor(new ArgTypeInfoRoslyn(typeof(T)), null, originalName, RawInfo.DummyProperty)
            {
                Name         = originalName,
                CliName      = commandLineName,
                Description  = description,
                DefaultValue = defaultValue,
            });

            commandDescriptor.AddOptions(options:
                                         new List <OptionDescriptor>()
            {
                option
            }
                                         );

            CliDescriptor = new CliDescriptor
            {
                GeneratedComandSourceNamespace  = GeneratedNamespace,
                GeneratedCommandSourceClassName = GeneratedSourceClassName,
                CommandDescriptor = commandDescriptor,
            };

            CommandDefinitionSourceCode = SourceCode;

            // TODO: figure out appropriate test action for use in dotnet interactive
        }
Exemple #6
0
        public string GetUsageForm(OptionDescriptor descr)
        {
            string optionName = null;

            if (null != descr.ShortNames && descr.ShortNames.Length > 0)
            {
                optionName = "-" + descr.ShortNames[0].ToString();
                if (descr.CanHaveValue)
                {
                    optionName += " ";
                    if (descr.MandatoryValue)
                    {
                        optionName += string.Format("<{0}>", descr.ValueIdentifier);
                    }
                    else
                    {
                        optionName += string.Format("[{0}]", descr.ValueIdentifier);
                    }
                }
            }
            else
            {
                optionName = "--" + descr.LongNames[0];
                if (descr.CanHaveValue)
                {
                    optionName += "=";
                    if (descr.MandatoryValue)
                    {
                        optionName += string.Format("[{0}]", descr.ValueIdentifier);
                    }
                    else
                    {
                        optionName += string.Format("<{0}>", descr.ValueIdentifier);
                    }
                }
            }

            if (descr.MandatoryOption)
            {
                optionName = "<" + optionName + ">";
            }
            else
            {
                optionName = "[" + optionName + "]";
            }

            return(optionName);
        }
        private CliDescriptor GetCliDescriptor()
        {
            var commandDescriptor = new CommandDescriptor(null, "MyClass", RawInfo.DummyClass)
            {
                Name = "my-class",
                // Parent = null,
            };
            // commandDescriptor.Root = commandDescriptor;
            var    testName                 = "testName";
            var    GeneratedNamespace       = "StarFruit2.Tests.TestSampleData" + testName;
            var    GeneratedSourceClassName = testName + "CommandSource";
            string originalName             = "SomeOption";
            string commandLineName          = "some-option";
            string description              = "desc";
            var    defaultValue             = new DefaultValueDescriptor("abc");

            var option = new OptionDescriptor(commandDescriptor, originalName, RawInfo.DummyProperty)
            {
                Name        = originalName,
                CliName     = commandLineName,
                Description = description,
            };

            option.Arguments.Add(new ArgumentDescriptor(new ArgTypeInfoRoslyn(typeof(string)), null, originalName, RawInfo.DummyProperty)
            {
                Name         = originalName,
                CliName      = commandLineName,
                Description  = description,
                DefaultValue = defaultValue,
            });

            commandDescriptor.AddOptions(options:
                                         new List <OptionDescriptor>()
            {
                option
            }
                                         );

            return(new CliDescriptor
            {
                GeneratedComandSourceNamespace = GeneratedNamespace,
                GeneratedCommandSourceClassName = GeneratedSourceClassName,
                CommandDescriptor = commandDescriptor,
            });
        }
Exemple #8
0
 public DLV2DesktopService(string exe_path) : base(exe_path)
 {
     load_from_STDIN_option  = "--stdin";
     competitionOutputOption = new OptionDescriptor("--competition-output");
 }
 private static NamedEntityDTO ToDTO <T, TOwner>(OptionDescriptor <T> option) where T : OptionEntity <TOwner>
 {
     return(new NamedEntityDTO(option.Option.Id, option.Option.Name));
 }
 private static BusinessRoleDTO ToDto(OptionDescriptor <ItSystemRole> availableRole)
 {
     return(new BusinessRoleDTO(availableRole.Option.Id, availableRole.Option.Name, false, availableRole.Option.HasWriteAccess, availableRole.Description));
 }
 public static OptionDescriptorAssertions Should(this OptionDescriptor instance)
 => new OptionDescriptorAssertions(instance);
Exemple #12
0
 private static BusinessRoleDTO ToDto(OptionDescriptor <DataProcessingRegistrationRole> availableRole)
 {
     return(new BusinessRoleDTO(availableRole.Option.Id, availableRole.Option.Name, false, availableRole.Option.HasWriteAccess, availableRole.Description));
 }
Exemple #13
0
 private static OptionWithDescriptionDTO ToDTO <T>(OptionDescriptor <T> option) where T : OptionEntity <DataProcessingRegistration>
 {
     return(new OptionWithDescriptionDTO(option.Option.Id, option.Option.Name, option.Description));
 }