private static async Task Main(string[] args) { Output.WriteHeader(); _cmdAllowedArgs = CmdAllowedArgsFactory.CreateCmdAllowedArgs(); var cmdArgInfo = new CmdArgInfo(args, _cmdAllowedArgs); CmdArg searchTermArg = cmdArgInfo.GetArgument('s'); CmdArg packageIdCsv = cmdArgInfo.GetArgument('i'); if (searchTermArg != null) { await SearchAsync(searchTermArg.Value); } else if (packageIdCsv != null) { var packageIds = packageIdCsv.Value.ToCsvList(); await GetByIdsAsync(packageIds); } else { HandleError("Provide either a search term or CSV list of package IDs argument."); } }
public void WhenArgNameHasTrailingSpace_ThenThrowException() { var args = new[] { "-a " }; var ex = Assert.Throws <CmdArgException>(() => _ = new CmdArgInfo(args, new[] { _allowedAllFilesArg })); Assert.That(ex.Message, Is.EqualTo("Argument name: 'a ' is not allowed.")); }
public void WhenTwoArgIsRequiredAndThreeSupplied_ThenThrowException() // aka same arg supplied more than once { var args = new[] { "-p", value, "-a", "-a" }; var ex = Assert.Throws <CmdArgException>(() => _ = new CmdArgInfo(args, new[] { _allowedPathArg, _allowedAllFilesArg })); Assert.That(ex.Message, Is.EqualTo("Allowed arguments 2 but 3 provided (p, a, a).")); }
public void WhenOneInputNameWithNoValue_ThenSetArguments() { var sut = new CmdArgInfo(new[] { "-a" }, new[] { _allowedPathArg, _allowedAllFilesArg }); Assert.That(sut.Arguments.Single().Value, Is.Null); AssertAreEqual(sut.Arguments.Single(), _allowedAllFilesArg); }
public ArgSettings(CmdArgInfo cmdArgInfo) { KeyVaultUri = cmdArgInfo.GetArgument('u')?.Value; FilePath = cmdArgInfo.GetArgument('p')?.Value; SectionName = cmdArgInfo.GetArgument('s')?.Value; if (cmdArgInfo. GetArgument('f') != null) UseFileOverwrite = true; }
public void WhenArgValidHasTrailingSpace_ThenKeepTrailingSpace() { var args = new[] { "-p", "Something " }; var sut = new CmdArgInfo(args, new[] { _allowedPathArg }); Assert.That(sut.Arguments.Single().ShortName, Is.EqualTo('p')); Assert.That(sut.Arguments.Single().Value, Is.EqualTo("Something ")); }
public void WhenOneArgIsRequiredAndNotPresent_ThenThrowException() { _allowedPathArg.IsRequired = true; var args = new[] { "-a" }; var ex = Assert.Throws <CmdArgException>(() => _ = new CmdArgInfo(args, new[] { _allowedPathArg, _allowedAllFilesArg })); Assert.That(ex.Message, Is.EqualTo($"Argument '{_allowedPathArg.ShortName}' is required and not supplied.")); }
public void WhenTwoLongInput_ValueArgFirst_ThenSetArguments() { var sut = new CmdArgInfo(new[] { "-path", value, "-allfiles" }, new[] { _allowedPathArg, _allowedAllFilesArg }); Assert.That(sut.Arguments.First().Value, Is.EqualTo(value)); AssertAreEqual(sut.Arguments.First(), _allowedPathArg); Assert.That(sut.Arguments.Second().Value, Is.Null); AssertAreEqual(sut.Arguments.Second(), _allowedAllFilesArg); }
public void WhenArgumentPresent_ThenReturnTrue() { var args = new[] { "-a" }; var sut = new CmdArgInfo(args, new[] { _allowedAllFilesArg }); var result = sut.HasArgument("allfiles"); Assert.That(result, Is.True); }
public void WhenArgumentNotPresent_ThenReturnFalse() { var args = new[] { "-p", value }; var sut = new CmdArgInfo(args, new[] { _allowedPathArg, _allowedAllFilesArg }); var result = sut.HasArgument("allfiles"); Assert.That(result, Is.False); }
public static List <string> GetSlnsToIgnore(this CmdArgInfo source) { var cmdArg = source.GetArgument('i'); if (cmdArg == null) { return(new List <string>()); } return(cmdArg.Value.Split(',').ToList()); }
public void WhenTwoArgIsRequiredAndNotPresent_ThenThrowException() { _allowedPathArg.IsRequired = true; _allowedAllFilesArg.IsRequired = true; var args = new string[0]; var ex = Assert.Throws <CmdArgException>(() => _ = new CmdArgInfo(args, new[] { _allowedPathArg, _allowedAllFilesArg })); var expectedMessage = $"Argument '{_allowedPathArg.ShortName}' is required and not supplied." + Environment.NewLine + $"Argument '{_allowedAllFilesArg.ShortName}' is required and not supplied."; Assert.That(ex.Message, Is.EqualTo(expectedMessage)); }
public void WhenTwoArgsIsRequired_AndAreBothPresent_ThenSetArguments() { _allowedPathArg.IsRequired = true; _allowedAllFilesArg.IsRequired = true; var args = new[] { "-p", value, "-a" }; var sut = new CmdArgInfo(args, new[] { _allowedPathArg, _allowedAllFilesArg }); Assert.That(sut.Arguments.First().Value, Is.EqualTo(value)); AssertAreEqual(sut.Arguments.First(), _allowedPathArg); Assert.That(sut.Arguments.Second().Value, Is.Null); AssertAreEqual(sut.Arguments.Second(), _allowedAllFilesArg); }
private static void Main(string[] args) { var sw = new Stopwatch(); sw.Start(); Output.WriteAppHeader(); _cmdAllowedArgs = CmdAllowedArgsFactory.Create(); try { _cmdArgInfo = new CmdArgInfo(args, _cmdAllowedArgs); CmdArg path = _cmdArgInfo.GetArgument('p'); CmdArg useTable = _cmdArgInfo.GetArgument('t'); var slnsToIgnore = _cmdArgInfo.GetSlnsToIgnore(); var slnPaths = GetSlnPaths(path.Value, slnsToIgnore); if (slnPaths.Count == 0) { HandleError($"{path.Value} and its sub directories contain no solution files."); } Output.WriteLine($"{slnPaths.Count} solutions found."); Output.WriteBlankLines(); if (useTable != null) { WriteSlnDetailsAsTable(slnPaths); } else { WriteSlnDetails(slnPaths); } } catch (Exception ex) { HandleError(ex.Message); } sw.Stop(); Output.WriteBlankLines(); Output.WriteLine($"Time taken: {sw.Elapsed.TotalSeconds} seconds."); Output.WriteBlankLines(); }
public ArgSettings(CmdArgInfo cmdArgInfo) { KeyVaultUri = cmdArgInfo.GetArgument('u')?.Value; FilePath = cmdArgInfo.GetArgument('p')?.Value; }
public ArgSettings(CmdArgInfo cmdArgInfo) { SectionName = cmdArgInfo.GetArgument('s')?.Value; KeyVaultUri = cmdArgInfo.GetArgument('u')?.Value; }
private static void Main(string[] args) { Output.WriteLine("ByteDev.Cmd.TestApp", new OutputColor(ConsoleColor.White, ConsoleColor.Blue)); Output.WriteLine(); var cmdAllowedArgs = new List <CmdAllowedArg> { new CmdAllowedArg('o', false) { LongName = "output", Description = "Test output" }, new CmdAllowedArg('m', false) { LongName = "messagebox", Description = "Test message box" }, new CmdAllowedArg('l', false) { LongName = "logger", Description = "Test logger" }, new CmdAllowedArg('t', false) { LongName = "table", Description = "Test table" }, new CmdAllowedArg('i', false) { LongName = "lists", Description = "Test Lists" } }; try { var cmdArgInfo = new CmdArgInfo(args, cmdAllowedArgs); if (cmdArgInfo.HasArguments) { foreach (var cmdArg in cmdArgInfo.Arguments) { switch (cmdArg.ShortName) { case 'o': Output.TestOutput(); break; case 'm': Output.TestMessageBox(); break; case 'l': TestLogger(); break; case 't': Output.TestTable(); break; case 'i': Output.TestLists(); break; } } } else { Output.WriteLine(cmdAllowedArgs.HelpText()); } } catch (CmdArgException ex) { Output.WriteLine(ex.Message, new OutputColor(ConsoleColor.Red)); Output.WriteLine(cmdAllowedArgs.HelpText()); } Prompt.PressAnyKey(); }
public void WhenInputArgsIsNull_ThenThrowException() { Assert.Throws <ArgumentNullException>(() => _ = new CmdArgInfo(null, new List <CmdAllowedArg>())); }