public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "dir|d=", "input directory containing NSA (and index) files to be merged", v => _inputDir = v }, { "out|o=", "output NSA file stub", v => _outFileStub = v } }; var commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckDirectoryExists(_inputDir, "input directory containing NSA files", "--in") .HasRequiredParameter(_outFileStub, "output NSA file stub", "--out") .SkipBanner() .ShowHelpMenu("Concatenate multiple (non-overlapping) NSA files from the same data source into one", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public async Task ConfigureServices_() { const int expectedReturnCode = 123456; const string expectedTextValue = "TestText"; var testService = A.Fake <ITestService>(); A.CallTo(() => testService.ReturnCode).Returns(expectedReturnCode); A.CallTo(() => testService.TextValue).Returns(expectedTextValue); var consoleApp = new ConsoleAppBuilder(Array.Empty <string>()) .ConfigureServices(x => x.AddTransient(_ => testService)) .UseProgramMain <TestServiceProgramMain>() .Build(); // Act var result = await consoleApp.RunAsync(); // Assert result .Should() .Be(expectedReturnCode); TestServiceProgramMain.TextValue .Should() .Be(expectedTextValue); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "ref|r=", "compressed reference sequence file", v => _compressedReference = v }, { "in|i=", "custom TSV file path", v => _inputFile = v }, { "out|o=", "output directory", v => _outputDirectory = v } }; string commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_compressedReference, "compressed reference sequence", "--ref") .CheckInputFilenameExists(_inputFile, "Custom variant annotation TSV", "--in") .CheckDirectoryExists(_outputDirectory, "output", "--out") .SkipBanner() .ShowHelpMenu("Creates a supplementary variant annotation database from a custom input file", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "in|i=", "OneKGenSv VCF file", v => _inputFileName = v }, { "out|o=", "output directory", v => _outputDirectory = v } }; string commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_inputFileName, "OneKGenSv VCF file", "--in") .CheckDirectoryExists(_outputDirectory, "output directory", "--out") .SkipBanner() .ShowHelpMenu("Convert the VCF file into BED-like format", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "tsv|t=", "input tsv file", v => _dosageSensitivityFile = v }, { "out|o=", "output directory", v => _outputDirectory = v } }; string commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .HasRequiredParameter(_outputDirectory, "output directory", "--out") .CheckDirectoryExists(_outputDirectory, "output directory", "--out") .CheckInputFilenameExists(_dosageSensitivityFile, "dosage sensitivity TSV file", "--tsv") .SkipBanner() .ShowHelpMenu("Creates a gene annotation database from dbVar data", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "ind|i=", "input NSA index file path", v => _inputIndexFile = v }, { "ver|r=", "version file path", v => _versionFile = v }, { "out|o=", "output index file path", v => _outputIndexFile = v } }; var commandLineExample = $"{command} --ind <input NSA index file path> --out <output index file path> --ver <version file path>"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_inputIndexFile, "input NSA index file path", "--ind") .HasRequiredParameter(_outputIndexFile, "output index file path", "--out") .CheckInputFilenameExists(_versionFile, "version file path", "--ver") .SkipBanner() .ShowHelpMenu("Extracts mini supplementary annotations for the given range from Nirvana Supplementary Annotations files.", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var creator = new GeneScoresMain(); var ops = new OptionSet { { "in|i=", "input gene scores {path}", v => _inputPath = v }, { "out|o=", "output directory {path}", v => _outputDirectory = v } }; var commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_inputPath, "gene scores file", "--in") .CheckDirectoryExists(_outputDirectory, "Output directory", "--out") .SkipBanner() .ShowHelpMenu("Reads provided OMIM data files and populates tsv file", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "uga|u=", "universal gene archive {path}", v => _universalGeneArchivePath = v }, { "ref|r=", "input reference {filename}", v => _inputReferencePath = v }, { "out|o=", "output directory", v => _outputDirectory = v } }; string commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .HasRequiredParameter(_outputDirectory, "output directory", "--out") .CheckDirectoryExists(_outputDirectory, "output directory", "--out") .CheckInputFilenameExists(_universalGeneArchivePath, "universal gene archive", "--uga") .SkipBanner() .ShowHelpMenu("Download the OMIM gene annotation data", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "in|i=", "input BED file path", v => _inputFile = v }, { "out|o=", "output directory", v => _outputDirectory = v } }; string commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_inputFile, "Mitochondrial Heteroplasmy BED file", "--in") .CheckDirectoryExists(_outputDirectory, "output directory", "--out") .SkipBanner() .ShowHelpMenu("Creates a TSV file with mitochondrial heteroplasmy information", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "i|in=", "Input XML {file}", v => _inputXmlFile = v }, { "a|acc=", "accessions", v => _accessions = v }, { "o|out=", "Output {dir}", v => _outputDir = v } }; var commandLineExample = $"{command} --in <xml file> --out <output Directory> --rcv <RCV ID>"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_inputXmlFile, "input XML file", "--in") .HasRequiredParameter(_outputDir, "output directory", "--out") .HasRequiredParameter(_accessions, "comma separated list of accessions or folder containing mini XML files to update", "--acc") .SkipBanner() .ShowHelpMenu("Extracts mini supplementary annotations for the given range from Nirvana Supplementary Annotations files.", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "uga|u=", "universal gene archive file path", v => _universalGeneArchivePath = v }, { "in|i=", "custom TSV file path", v => _inputFile = v }, { "out|o=", "output directory", v => _outputDirectory = v } }; string commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_universalGeneArchivePath, "universal gene archive", "--uga") .CheckInputFilenameExists(_inputFile, "Custom gene annotation TSV", "--in") .CheckDirectoryExists(_outputDirectory, "output", "--out") .SkipBanner() .ShowHelpMenu("Creates a supplementary gene annotation database from a custom input file", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "tsv|t=", "input tsv file", v => _dosageMapRegionFile = v }, { "ref|r=", "input reference {filename}", v => _inputReferencePath = v }, { "out|o=", "output directory", v => _outputDirectory = v } }; string commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_dosageMapRegionFile, "dosage map region TSV file", "--tsv") .CheckInputFilenameExists(_inputReferencePath, "reference sequence file", "--tsv") .CheckDirectoryExists(_outputDirectory, "output directory", "--out") .SkipBanner() .ShowHelpMenu("Creates an interval annotation database from dbVar data", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "ref|r=", "compressed reference sequence file", v => _compressedReference = v }, { "in|i=", "MITOMAP structural variants HTML file", v => MitoMapFileNames.Add(v) }, { "out|o=", "output directory", v => _outputDirectory = v } }; string commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_compressedReference, "compressed reference sequence file name", "--ref") .CheckEachFilenameExists(MitoMapFileNames, "MITOMAP structural variants HTML file", "--in") .CheckDirectoryExists(_outputDirectory, "output directory", "--out") .SkipBanner() .ShowHelpMenu("Creates a supplementary database with MITOMAP structural variants annotations", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static int Main(string[] args) { var ops = new OptionSet { { "ga=", "genome assembly {version}", v => _genomeAssembly = v }, { "out|o=", "top-level output {directory}", v => _outputDirectory = v } }; var exitCode = new ConsoleAppBuilder(args, ops) .Parse() .HasRequiredParameter(_genomeAssembly, "genome assembly", "--ga") .CheckDirectoryExists(_outputDirectory, "top-level output directory", "--out") .ShowBanner(Constants.Authors) .ShowHelpMenu("Downloads the Nirvana data files from S3", "--ga <genome assembly> --out <output directory>") .ShowErrors() .Execute(ProgramExecution); return((int)exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "src|s=", "VCF file with dbSNP ids and data to be remapped", v => _srcMapFile = v }, { "des|d=", "VCF file (with same chromosome order as src) with destination dbSNP mapping", v => _destMapFile = v } }; var commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_srcMapFile, "VCF file with dbSNP ids and data to be remapped", "--src") .CheckInputFilenameExists(_destMapFile, "VCF file with destination dbSNP mapping", "--des") .SkipBanner() .ShowHelpMenu("Reads provided supplementary data files and populates tsv files", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static int Main(string[] args) { var ops = new OptionSet { { "header|t", "print also the header lines", v => _printHeader = v != null }, { "only-header|H", "print only the header lines", v => _printHeaderOnly = v != null }, { "list|l", "list chromosome and section names", v => _list = v != null }, { "index|c", "create index", v => _createIndex = v != null }, { "in|i=", "input", v => _inputJson = v }, { "out|o=", "compressed output file name (default:console)", v => _outputFile = v }, { "query|q=", "query range", v => Queries.Add(v) }, { "section|s=", "complete section (positions or genes) to output", v => _section = v } }; var exitCode = new ConsoleAppBuilder(args, ops) .Parse() .CheckInputFilenameExists(_inputJson, "input Json file", "[in.json.gz]") .DisableOutput(!_createIndex && _outputFile == null) .ShowBanner(Constants.Authors) .ShowHelpMenu("Indexes a Nirvana annotated JSON file", "-i in.json.gz [options]") .ShowErrors() .Execute(ProgramExecution); return((int)exitCode); }
public void ShowBanner_EnabledOutput() { var ops = new OptionSet { { "test=", "test", v => { } } }; var banner = new ConsoleAppBuilder(null, ops).UseVersionProvider(new VersionProvider()) .Parse() .ShowBanner("authors"); Assert.True(banner is ConsoleAppBanner); }
public void Build_NoCommandAndProgramMainGiven_ThrowsException() { var builder = new ConsoleAppBuilder(Array.Empty <string>()); // Act Action act = () => builder.Build(); // Assert act .Should() .Throw <InvalidOperationException>(); }
public void VersionProvider_Set() { var ops = new OptionSet { { "test=", "test", v => { } } }; var data = new ConsoleAppBuilder(null, ops).UseVersionProvider(new VersionProvider()) .Parse() .Data; Assert.True(data.VersionProvider is VersionProvider); }
public static ExitCodes Run(string command, string[] commandArgs) { var ops = new OptionSet { { "ref|r=", "compressed reference sequence file", v => _compressedReference = v }, { "cache|c=", "Transcript cache prefix", v => _transcriptCachePrefix = v }, { "gene|g=", "Gene info data file from NCBI", v => _geneInfoFile = v }, { "in|i=", "input VCF file path", v => _inputFile = v }, { "out|o=", "output directory", v => _outputDirectory = v } }; string commandLineExample = $"{command} [options]"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_compressedReference, "compressed reference sequence file name", "--ref") .HasRequiredParameter(_transcriptCachePrefix, "transcript cache file", "--cache") .CheckInputFilenameExists(CacheConstants.TranscriptPath(_transcriptCachePrefix), "transcript cache prefix", "--cache") .HasRequiredParameter(_inputFile, "SpliceAI VCF file", "--in") .CheckInputFilenameExists(_inputFile, "SpliceAI VCF file", "--in") .HasRequiredParameter(_geneInfoFile, "Gene info data file from NCBI", "--gene") .CheckInputFilenameExists(_geneInfoFile, "Gene info data file from NCBI", "--gene") .HasRequiredParameter(_outputDirectory, "output directory", "--out") .CheckDirectoryExists(_outputDirectory, "output directory", "--out") .SkipBanner() .ShowHelpMenu("Creates a supplementary database containing 1000 Genomes allele frequencies", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public static ExitCodes Run(string command, string[] commandArgs) { var extractor = new ExtractMiniSaMain(); var ops = new OptionSet { { "ref|r=", "compressed reference sequence file", v => _compressedReference = v }, { "in|i=", "input Nirvana Supplementary Annotations {file}", v => _inputSuppAnnotPath = v }, { "name|n=", "data source {name}", v => _dataSourceName = v }, { "begin|b=", "reference begin {position}", (int v) => _begin = v }, { "end|e=", "reference end {allele}", (int v) => _end = v }, { "out|o=", "output {directory}", v => _miniSaDirectory = v } }; var commandLineExample = $"{command} --in <Supplementary Annotations path> --out <Supplementary Annotations Directory> --begin <position> --end <position> --name <dataSource>"; var exitCode = new ConsoleAppBuilder(commandArgs, ops) .Parse() .CheckInputFilenameExists(_inputSuppAnnotPath, "Nirvana supplementary annotations", "--in") .CheckInputFilenameExists(_compressedReference, "Compressed reference sequence file name", "--ref") .HasRequiredParameter <string>(_miniSaDirectory, "output directory", "--out") .SkipBanner() .ShowHelpMenu("Extracts mini supplementary annotations for the given range from Nirvana Supplementary Annotations files.", commandLineExample) .ShowErrors() .Execute(ProgramExecution); return(exitCode); }
public void HasRequiredDate_Exists_BadFormat() { string observedDate = default; var ops = new OptionSet { { "date=", "date", v => observedDate = v } }; var validator = new ConsoleAppBuilder(new[] { "--date", "garbage" }, ops) .Parse() .HasRequiredDate(observedDate, "date", "--date"); Assert.True(validator.Data.Errors.Count > 0); }
public void Parse_UnsupportedOption() { var ops = new OptionSet { { "test=", "test", v => { } } }; var data = new ConsoleAppBuilder(new[] { "--if", "-" }, ops) .Parse() .Data; Assert.Single(data.Errors); Assert.Equal(2, data.UnsupportedOps.Count); }
public void CheckOutputFilenameSuffix_False() { var ops = new OptionSet { { "date=", "date", v => { } } }; var validator = new ConsoleAppBuilder(new[] { "--date", "2018-03-14" }, ops) .Parse() .CheckOutputFilenameSuffix("test.json", ".gz", "temp"); Assert.NotEqual(ExitCodes.Success, validator.Data.ExitCode); Assert.True(validator.Data.Errors.Count > 0); }
public void Build_ProgramMainHasPrivateCtor_ThrowsException() { var builder = new ConsoleAppBuilder(Array.Empty <string>()); builder.UseProgramMain <TestProgramMainWithPrivateCtor>(); // Act Action act = () => builder.Build(); // Assert act .Should() .Throw <InvalidOperationException>(); }
public void Build_ProgramMainHasInvalidCtorArgs_ReturnsIntMinValue() { var builder = new ConsoleAppBuilder(Array.Empty <string>()); builder.UseProgramMain <TestProgramMainWithInvalidCtorArgs>(); // Act Action act = () => builder.Build(); // Assert act .Should() .Throw <InvalidOperationException>(); }
public async Task RunSync_DifferentRoutesToDefaultAction_ActionIsExecuted(params string[] args) { var consoleApp = new ConsoleAppBuilder(args) .UseActions(x => x.AddController <TestMultiRouteCliController>().UseMiddleware <CliRoutingMiddleware>()) .Build(); // Act var result = await consoleApp.RunAsync(); // Assert result .Should() .Be(TestMultiRouteCliController.ExecuteReturnCode); }
public void Build_WithStartup_StartupCreatedAndCalled() { var builder = new ConsoleAppBuilder(Array.Empty <string>()); builder.UseProgramMain <TestProgramMain>(); builder.UseStartup <TestStartup>(); // Act var _ = builder.Build(); // Assert TestStartup.ConfigureServicesIsCalled .Should() .BeTrue(); }
///------------------------------------------------------------------------------------------------- /// <summary> Registers an executor for a main program. </summary> /// /// <exception cref="InvalidOperationException"> Thrown when the program main class could not /// be created. </exception> /// /// <typeparam name="TProgramMain"> Type of the program main class. </typeparam> /// <param name="consoleAppBuilder"> The consoleAppBuilder to act on. </param> /// /// <returns> The ConsoleAppBuilder. </returns> ///------------------------------------------------------------------------------------------------- public static ConsoleAppBuilder UseProgramMain <TProgramMain>(this ConsoleAppBuilder consoleAppBuilder) where TProgramMain : IMain { return(consoleAppBuilder.UseExecutor(sp => { var main = typeof(TProgramMain).CreateInstance <IMain>(sp); if (main == null) { throw new InvalidOperationException(); } return new MainExecutor(main); })); }
public void Parse_ShowOutput() { var ops = new OptionSet { { "test=", "test", v => { } } }; var exitCode = new ConsoleAppBuilder(new[] { "--test", "test" }, ops) .Parse() .ShowBanner("authors") .ShowHelpMenu("description", "example") .ShowErrors() .Execute(() => ExitCodes.Success); Assert.Equal(ExitCodes.Success, exitCode); }