public void BasicTest() { var options = new OptionSet(); options = options.PassThroughAllSerializers(); options.Items.Count.Should().Be(0); options.Set("A"); options = options.PassThroughAllSerializers(); options.Get <string>().Should().Be("A"); options.GetRequiredService <string>().Should().Be("A"); options.Items.Count.Should().Be(1); options.Set("B"); options = options.PassThroughAllSerializers(); options.Get <string>().Should().Be("B"); options.GetRequiredService <string>().Should().Be("B"); options.Items.Count.Should().Be(1); options.Remove <string>(); options = options.PassThroughAllSerializers(); options.GetOrDefault <string>("").Should().Be(""); options.Get <string>().Should().BeNull(); options.GetService <string>().Should().Be(null); options.Items.Count.Should().Be(0); options.Set("C"); options.Clear(); options.Items.Count.Should().Be(0); }
public void BasicTest() { var options = new OptionSet(); options = options.PassThroughAllSerializers(); options.Items.Count.Should().Be(0); options.Set("A"); options = options.PassThroughAllSerializers(); options.Get <string>().Should().Be("A"); options.GetRequiredService <string>().Should().Be("A"); options.Items.Count.Should().Be(1); options.Set("B"); options = options.PassThroughAllSerializers(); options.Get <string>().Should().Be("B"); options.GetRequiredService <string>().Should().Be("B"); options.Items.Count.Should().Be(1); options.Remove <string>(); options = options.PassThroughAllSerializers(); options.TryGet <string>().Should().Be(null); Assert.Throws <KeyNotFoundException>(() => { options.Get <string>(); }); options.GetService <string>().Should().Be(null); options.Items.Count.Should().Be(0); options.Set("C"); options.Clear(); options.Items.Count.Should().Be(0); }
protected override OptionSet PopulateCustomOptionSet(OptionSet options) { options.Clear(); options.Add("host=", "Database server host", s => AddArgument("host", s)) .Add("port=", "Database server port", s => AddArgument("port", s)) .Add("user="******"Database user", s => AddArgument("user", s)) .Add("database=", "Database name", s => AddArgument("database", s)) .Add("password="******"Database password", s => AddArgument("password", s)) .Add("provider=", "Database provider", s => AddArgument("provider", s)); return(options); }
/// <summary> /// Creates a new bootstrap process. /// </summary> /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</param> /// <param name="gui"><c>true</c> if the application was launched in GUI mode; <c>false</c> if it was launched in command-line mode.</param> public BootstrapProcess(ITaskHandler handler, bool gui) : base(handler) { _gui = gui; _options = new OptionSet { { "?|h|help", () => "Show the built-in help text.", _ => { Handler.Output("Help", HelpText); throw new OperationCanceledException(); // Don't handle any of the other arguments } }, { "batch", () => "Automatically answer questions with defaults when possible. Avoid unnecessary console output (e.g. progress bars).", _ => { if (Handler.Verbosity >= Verbosity.Verbose) { throw new OptionException("Cannot combine --batch and --verbose", "verbose"); } Handler.Verbosity = Verbosity.Batch; } }, { "v|verbose", () => "More verbose output. Use twice for even more verbose output.", _ => { if (Handler.Verbosity == Verbosity.Batch) { throw new OptionException("Cannot combine --batch and --verbose", "batch"); } Handler.Verbosity++; } }, { "no-existing", () => "Do not detect and use existing Zero Install instances. Always use downloaded and cached instance.", _ => _noExisting = true }, { "version=", () => "Select a specific {VERSION} of Zero Install. Implies --no-existing.", (VersionRange range) => { _version = range; _noExisting = true; } }, { "feed=", () => "Specify an alternative {FEED} for Zero Install. Must be an absolute URI. Implies --no-existing.", feed => { Config.SelfUpdateUri = new FeedUri(feed); _noExisting = true; } }, { "content-dir=", () => "Specifies a {DIRECTORY} to search for feeds and archives to import. The default is a directory called 'content'.", path => { if (!Directory.Exists(path)) { throw new DirectoryNotFoundException($"Directory '{path}' not found."); } _contentDir = path; } }, { "o|offline", () => "Run in off-line mode, not downloading anything.", _ => Config.NetworkUse = NetworkLevel.Offline }, // Disable interspersed arguments (needed for passing arguments through to target) { "<>", value => { _targetArgs.Add(value); // Stop using options parser, treat everything from here on as unknown _options.Clear(); } } }; }