示例#1
0
        protected void ParseCommandLine(string[] args)
        {
            try
            {
                _commandLineOps["version"] = new TopLevelOption("displays the version", null);

                string command = null;
                Func <string, string[], int> commandMethod = null;
                string unsupportedOp = null;

                if (args == null || args.Length == 0)
                {
                    SetExitCode(ExitCodes.MissingCommandLineOption);
                    _showHelpMenu = true;
                }
                else
                {
                    command = args[0].ToLower();
                    if (command == "version")
                    {
                        _showVersion = true;
                    }

                    commandMethod = GetCommandMethod(command);
                    if (commandMethod == null)
                    {
                        unsupportedOp = command;
                    }
                }

                if (_showVersion)
                {
                    Console.WriteLine("{0} {1}", _versionProvider.GetProgramVersion(), _versionProvider.GetDataVersion());
                    SetExitCode(ExitCodes.Success);
                }
                else
                {
                    if (_showHelpMenu)
                    {
                        CommandLineUtilities.DisplayBanner(_programAuthors);
                        ShowHelpMenu(unsupportedOp);
                    }
                    else
                    {
                        if (FoundParsingErrors())
                        {
                            return;
                        }
                        if (commandMethod != null)
                        {
                            ExitCode = commandMethod(command, args.Skip(1).ToArray());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ExitCode = ExitCodeUtilities.ShowException(e);
            }
        }
 public void DisplayBannerLongAuthorName()
 {
     Assert.Throws <GeneralException>(
         () =>
         CommandLineUtilities.DisplayBanner(
             "Lopado­temacho­selacho­galeo­kranio­leipsano­drim­hypo­trimmato­silphio­parao­melito­katakechy­meno­kichl­epi­kossypho­phatto­perister­alektryon­opte­kephallio­kigklo­peleio­lagoio­siraio­baphe­tragano­pterygon"));
 }
示例#3
0
 public IConsoleAppBanner ShowBanner(string authors)
 {
     if (Data.ShowVersion)
     {
         Console.WriteLine($"{CommandLineUtilities.Title} {CommandLineUtilities.InformationalVersion} {Data.VersionProvider.DataVersion}");
     }
     else if (!Data.DisableOutput)
     {
         CommandLineUtilities.DisplayBanner(authors);
     }
     return(new ConsoleAppBanner(Data));
 }
示例#4
0
        private static void DisplayHelp()
        {
            CommandLineUtilities.DisplayBanner(Constants.Authors);
            Console.WriteLine("Usage: SAUtils <command> [options]");
            Console.WriteLine();
            Console.WriteLine("Commands: ");
            var filler  = new string(' ', 7);
            var filler2 = new string(' ', 10);

            Console.WriteLine(filler + "createCI" + filler2 + "Create customeIntervals");

            Console.WriteLine(filler + "createSA" + filler2 + "Create supplementary database");
            Console.WriteLine(filler + "createOMIM" + filler2 + "Create OMIM database");
        }
        public void DisplayBanner()
        {
            string result;

            using (var redirector = new ConsoleRedirector())
            {
                CommandLineUtilities.DisplayBanner("BOB");
                result = redirector.ToString();
                redirector.Close();
            }

            Assert.Contains("testhost", result);
            Assert.Contains("BOB", result);
            Assert.Contains("(c) 2017 Illumina, Inc.", result);
            Assert.Contains("15.0.0", result);
        }
        /// <summary>
        /// executes the command-line workflow
        /// </summary>
        public void Execute(string[] args)
        {
            var bench = new Benchmark();

            try
            {
                List <string> unsupportedOps = null;

                if (args == null || args.Length == 0)
                {
                    SetExitCode(ExitCodes.MissingCommandLineOption);
                    _showHelpMenu = true;
                }
                else
                {
                    try
                    {
                        unsupportedOps = _commandLineOps.Parse(args);

                        if (unsupportedOps.Count > 0)
                        {
                            SetExitCode(ExitCodes.UnknownCommandLineOption);
                            _showHelpMenu = true;
                        }
                    }
                    catch (OptionException oe)
                    {
                        _errorBuilder.AppendFormat("{0}ERROR: {1}\n", _errorSpacer, oe.Message);
                        SetExitCode(ExitCodes.UnknownCommandLineOption);
                        _showHelpMenu = true;
                    }
                }

                if (_showVersion)
                {
                    Console.WriteLine("{0} {1}", _versionProvider.GetProgramVersion(), _versionProvider.GetDataVersion());
                    SetExitCode(ExitCodes.Success);
                }
                else
                {
                    if (!Console.IsOutputRedirected)
                    {
                        CommandLineUtilities.DisplayBanner(_programAuthors);
                    }

                    if (_showHelpMenu)
                    {
                        Help.Show(_commandLineOps, _commandLineExample, _programDescription);

                        CommandLineUtilities.ShowUnsupportedOptions(unsupportedOps);

                        Console.WriteLine();
                        Console.WriteLine(_versionProvider.GetDataVersion());
                        Console.WriteLine();

                        // print the errors if any were found
                        if (FoundParsingErrors())
                        {
                            return;
                        }
                    }
                    else
                    {
                        ValidateCommandLine();

                        // print the errors if any were found
                        if (FoundParsingErrors())
                        {
                            return;
                        }

                        ProgramExecution();
                    }
                }
            }
            catch (Exception e)
            {
                ExitCode = ExitCodeUtilities.ShowException(e);
            }

            _peakMemoryUsageBytes = MemoryUtilities.GetPeakMemoryUsage();
            _wallTimeSpan         = bench.GetElapsedTime();

            if (!_showVersion && !_showHelpMenu && !Console.IsOutputRedirected)
            {
                Console.WriteLine();
                if (_peakMemoryUsageBytes > 0)
                {
                    Console.WriteLine("Peak memory usage: {0}", MemoryUtilities.ToHumanReadable(_peakMemoryUsageBytes));
                }
                Console.WriteLine("Time: {0}", Benchmark.ToHumanReadable(_wallTimeSpan));
            }
        }