public DependencyListOptions(Reports reports, CommandArgument path, CommandOption framework) { bool isInputValid = true; // reports Reports = reports; // project var projectPath = path.Value ?? Directory.GetCurrentDirectory(); Runtime.Project projectOption; isInputValid &= Runtime.Project.TryGetProject(projectPath, out projectOption); Path = projectPath; Project = projectOption; // framework if (framework.HasValue()) { try { Framework = VersionUtility.ParseFrameworkName(framework.Value()); } catch (ArgumentException ex) { Reports.Error.WriteLine("Invalid framework name: {0}. [{1}]", framework.Value(), ex.Message); isInputValid = false; } } else { Framework = null; } Valid = isInputValid; }
private DbMigrationsConfiguration GetConfiguration(CommandOption connectionStringOption, CommandOption providerNameOption) { var connectionString = connectionStringOption.HasValue() ? connectionStringOption.Value() : null; var providerName = providerNameOption.HasValue() ? providerNameOption.Value() : null; return _migrator.GetConfiguration(connectionString, providerName: providerName); }
public CommandOption Option(string template, string description, CommandOptionType optionType, Action<CommandOption> configuration) { var option = new CommandOption(template, optionType) { Description = description }; Options.Add(option); configuration(option); return option; }
public void Options_UseCorrectName_Returns_CorrectValue( string propertyName, string expectedOptionTemplate, string expectedOptionDescription, int expectedCommandOptionType, string commandLineStringWithTheOption, object expectedValueWhenOptionIsPresent, object expectedValueWhenOptionIsNotPresent) { //Arrange var command = new CommandLineApplication(); var property = typeof(TestClass).GetProperty(propertyName); var descriptor = new ParameterDescriptor(property); var expectedOption = new CommandOption(expectedOptionTemplate, (CommandOptionType)expectedCommandOptionType); //Act descriptor.AddCommandLineParameterTo(command); //Assert var actualOption = command.Options.First(); Assert.Equal(expectedOption.LongName, actualOption.LongName); Assert.Equal(expectedOption.ShortName, actualOption.ShortName); Assert.Equal(expectedOption.OptionType, actualOption.OptionType); Assert.Equal(expectedOptionDescription, actualOption.Description); //Arrange command.Execute(new string[0] { }); //Assert Assert.Equal(expectedValueWhenOptionIsNotPresent, descriptor.Value); //Arrange command.Execute(commandLineStringWithTheOption.Split(' ')); //Assert Assert.Equal(expectedValueWhenOptionIsPresent, descriptor.Value); }