public void Model_to_descriptor(Type type) { var testData = Activator.CreateInstance(type) as BaseTestData; CliDescriptor actual = Utils.GetCliFromFile(testData.ModelCodeFileName); actual.Should().Match(testData.CliDescriptor); }
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 SeveralOptionsAndArgumentsTestData() // string originalName, // string commandLineName, // string typeStringRepresentation, // string? description, // DefaultValueDescriptor? defaultValue) : base("SeveralOptionsAndArguments") { string sourceCode = $@"NOT YET IMPLEMENTED: Read corresponding file"; var commandDescriptor = new CommandDescriptor(null, "MyClass", RawInfo.DummyClass) { Name = "my-class" }; commandDescriptor.AddArguments(arguments: new List <ArgumentDescriptor>() { new ArgumentDescriptor(new ArgTypeInfoRoslyn(typeof(string)), null, "MyArgPropertyArg", RawInfo.DummyProperty) { Name = "MyArgPropertyArg", CliName = "my-property-arg", }, }); commandDescriptor.AddOptions(options: new List <OptionDescriptor>() { new OptionDescriptor(null, "MyProperty", RawInfo.DummyProperty) { Name = "MyProperty", CliName = "my-property", }, new OptionDescriptor(null, "MyProperty2", RawInfo.DummyProperty) { Name = "MyProperty2", CliName = "my-property2", }, new OptionDescriptor(null, "MyProperty3", RawInfo.DummyProperty) { Name = "MyProperty3", CliName = "my-property2", }, }); CliDescriptor = new CliDescriptor { GeneratedComandSourceNamespace = "StarFruit2.Tests.TestSampleData.SeveralOptionsAndArguments", GeneratedCommandSourceClassName = "SeveralOptionsAndArgumentsCommandSource", CommandDescriptor = commandDescriptor, }; CommandDefinitionSourceCode = sourceCode; // TODO: figure out appropriate test action for use in dotnet interactive // it might be an action passed into constructor }
internal static CliDescriptor WrapInCliDescriptor(this ArgumentDescriptor argumentDescriptor) { var clidDescriptor = new CliDescriptor() { CommandDescriptor = new CommandDescriptor(null, "MyClass", RawInfo.DummyClass), GeneratedComandSourceNamespace = "MyNamespace" }; clidDescriptor.CommandDescriptor.Arguments.Add(argumentDescriptor); return(clidDescriptor); }
public virtual CliDescriptor CreateCliDescriptor <TCommandSymbol>(ISymbolDescriptor?parent, TCommandSymbol symbol) where TCommandSymbol : class, ISymbol { var cliDesriptor = new CliDescriptor { GeneratedComandSourceNamespace = symbol.ContainingNamespace.ToString(), CommandDescriptor = CreateCommandDescriptor(parent, symbol) }; return(cliDesriptor); }
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 }
public SeveralSubCommandsTestData() : base("SeveralSubCommands") { string sourceCode = $@"NOT YET IMPLEMENTED: Read corresponding file"; var commandDescriptor = new CommandDescriptor(null, "MyClass", RawInfo.DummyClass) { Name = "my-class" }; commandDescriptor.AddCommands(subCommands: new List <CommandDescriptor>() { new CommandDescriptor(null, "MyMethod2", RawInfo.DummyClass) { Name = "MyMethod2", CliName = "my-mymethod2", }, new CommandDescriptor(null, "MyMethod1", RawInfo.DummyClass) { Name = "MyMethod1", CliName = "my-mymethod1", }, new CommandDescriptor(null, "MyMethod3", RawInfo.DummyClass) { Name = "MyMethod3", CliName = "my-mymethod3", }, }); commandDescriptor.SubCommands.First().AddArguments(arguments: new List <ArgumentDescriptor>() { new ArgumentDescriptor(new ArgTypeInfoRoslyn(typeof(int)), null, "myParam", RawInfo.DummyMethod) { Name = "myParam", CliName = "my-param", }, }); CliDescriptor = new CliDescriptor { GeneratedComandSourceNamespace = "StarFruit2.Tests.TestSampleData.SeveralSubCommands", GeneratedCommandSourceClassName = "SeveralSubCommandsCommandSource", CommandDescriptor = commandDescriptor, }; CommandDefinitionSourceCode = sourceCode; // TODO: figure out appropriate test action for use in dotnet interactive // it might be an action passed into constructor }
public void Command_with_argument(bool useVB) { var descriptor = new CliDescriptor { CommandDescriptor = new CommandDescriptor(null, "MyCommand", new RawInfoForType(null, namespaceName, className)) }; descriptor.CommandDescriptor.Arguments.Add(new ArgumentDescriptor(new ArgTypeInfoRoslyn(typeof(string)), descriptor.CommandDescriptor, "Argument1", new RawInfoForProperty(null, namespaceName, className))); var dom = new GenerateCommandSource().CreateCode(descriptor); var actual = Utils.Generator(useVB).Generate(dom); NamerFactory.AdditionalInformation = Utils.LanguageName(useVB); Approvals.Verify(actual); }
public virtual Code CreateCode(CliDescriptor cli, IEnumerable <Using>?sourceUsings = null) { _ = cli ?? throw new InvalidOperationException("CliDescriptor cannot be null"); var cmd = cli.CommandDescriptor; return(Code.Create(cli.GeneratedComandSourceNamespace) .Usings("StarFruit2") .Usings("System.CommandLine") .Usings("StarFruit2.Common") .Usings("System.CommandLine.Invocation") .Usings("System.CommandLine.Parsing") .Usings(sourceUsings) .Class(CommandResultClass(cmd, BaseType(cmd))) .Classes(cmd.SubCommands, c => CommandResultClass(c, (c.ParentSymbolDescriptorBase as CommandDescriptor)?.CommandSourceResultClassName() ?? "<missing name>")));
public void Command_with_option(bool useVB) { var descriptor = new CliDescriptor { CommandDescriptor = new CommandDescriptor(null, "MyCommand", new RawInfoForType(null, namespaceName, className)) }; descriptor.CommandDescriptor.Options.Add(new OptionDescriptor(descriptor.CommandDescriptor, "Option1", new RawInfoForProperty(null, namespaceName, className))); var dom = new GenerateCommandSource().CreateCode(descriptor); var actual = Utils.Generator(useVB).Generate(dom); NamerFactory.AdditionalInformation = Utils.LanguageName(useVB); Approvals.Verify(actual); }
public void Simple_command(bool useVB) { var descriptor = new CliDescriptor { CommandDescriptor = new CommandDescriptor(null, "MyCommand", new RawInfoForType(null, namespaceName, className)) }; descriptor.CommandDescriptor.CliName = "my-command"; var dom = new GenerateCommandSource().CreateCode(descriptor); var actual = Utils.Generator(useVB).Generate(dom); NamerFactory.AdditionalInformation = Utils.LanguageName(useVB); Approvals.Verify(actual); }
public virtual Code CreateCode(CliDescriptor cli, IEnumerable <Using>?sourceUsings = null) { var cmd = cli.CommandDescriptor; return(Code.Create(cli.GeneratedComandSourceNamespace) .Usings("StarFruit2") .Usings("System.CommandLine") .Usings("StarFruit2.Common") .Usings("System.CommandLine.Invocation") .Usings("System.CommandLine.Parsing") .Usings(sourceUsings) .Class(CommandSourceClass(cmd, new TypeRep("RootCommandSource", cmd.CommandSourceClassName()), null)) .Classes(new CommandDescriptor[] { cmd }, c => SubCommandClasses(c))); }
public SingleArgTestData(string testName, string originalName, string name, string commandLineName, string typeStringRepresentation, string?description, DefaultValueDescriptor?defaultValue) : base(testName) { string sourceCode = $@" var command = new Command(""MyClass"", """"); command.Arguments.Add(GetArg<{typeStringRepresentation}>(""{commandLineName}"", ""{description}"", {defaultValue.CodeRepresentation})); return command;"; GeneratedNamespace = "StarFruit2.Tests.TestSampleData." + testName; GeneratedSourceClassName = testName + "CommandSource"; var commandDescriptor = CommandDescriptor; commandDescriptor.AddArguments(arguments: new List <ArgumentDescriptor>() { new ArgumentDescriptor(new ArgTypeInfoRoslyn(typeof(T)), null, originalName, RawInfo.DummyProperty) { Name = name, CliName = commandLineName, Description = description, DefaultValue = defaultValue, } }); CliDescriptor = new CliDescriptor { GeneratedComandSourceNamespace = GeneratedNamespace, GeneratedCommandSourceClassName = GeneratedSourceClassName, CommandDescriptor = commandDescriptor, }; CommandDefinitionSourceCode = sourceCode; // TODO: figure out appropriate test action for use in dotnet interactive // it might be an action passed into constructor }
public EmptyTestData() : base(testName) { GeneratedNamespace = generatedNamespace; GeneratedSourceClassName = generatedClassName; CliDescriptor = new CliDescriptor { GeneratedComandSourceNamespace = generatedNamespace, GeneratedCommandSourceClassName = generatedClassName, CommandDescriptor = new CommandDescriptor(null, "MyClass", RawInfo.DummyClass) { Name = "MyClass" } }; CommandDefinitionSourceCode = @$ " var command = new Command(" "{SystemCommandLineName}" ", " "{CliDescriptor.CommandDescriptor.Description}" "); return command;"; TestAction = c => c.Name.Should().Be("my-class"); }
public static CliDescriptorAssertions Should(this CliDescriptor instance) => new CliDescriptorAssertions(instance);