Esempio n. 1
0
        public void Invoke(IConsoleHost consoleHost, string[] args)
        {
            var commandName = args[0];

            try
            {
                var options = CommandLineSwitch.Parse <Options>(ref args);
                if (args.Skip(1).Any() == false || options.Help)
                {
                    Usage(consoleHost, commandName);
                    return;
                }

                var found = _Fonts.Value.TryGetValue(options.Font.ToLower(), out var getFont);
                if (!found)
                {
                    throw new FontNotFoundException(options.Font);
                }

                var bannerText = getFont().Render(string.Join(' ', args.Skip(1)));
                consoleHost.WriteLine(bannerText);
            }

            catch (FontNotFoundException e) { consoleHost.WriteLine(Yellow(e.Message)); }
            catch (InvalidCommandLineSwitchException e)
            {
                consoleHost.WriteLine(Yellow(e.Message));
                Usage(consoleHost, commandName);
            }
        }
Esempio n. 2
0
        public void Parse_Enum_Test()
        {
            var args    = "-t svn commit".Split(' ');
            var options = CommandLineSwitch.Parse <VCSCommandOptions>(ref args);

            options.Type.Is(VCSTypes.SVN);
            args.Is("commit");
        }
Esempio n. 3
0
        public void Parse_LongNameOnly_Test()
        {
            var args    = "http://localhost:32767 --authenticationtype cookie --allowanonymous".Split(' ');
            var options = CommandLineSwitch.Parse <HttpServerOptions>(ref args);

            options.AuthenticationType.Is(AuthenticationType.Cookie);
            options.AllowAnonymous.IsTrue();
        }
Esempio n. 4
0
        public void EmptyArgs_Test()
        {
            var args    = new string[] { };
            var options = CommandLineSwitch.Parse <HttpServerOptions>(ref args);

            options.Recursive.Is(false);
            options.Port.Is <uint>(8080);
            args.Is();
        }
Esempio n. 5
0
        public void ComplexArgs_Test()
        {
            var args    = new[] { "--port", "80", @"c:\wwwroot\inetpub", "-r" };
            var options = CommandLineSwitch.Parse <HttpServerOptions>(ref args);

            options.Recursive.Is(true);
            options.Port.Is <uint>(80);
            args.Is(@"c:\wwwroot\inetpub");
        }
Esempio n. 6
0
        public static async Task <int> Main(string[] args)
        {
            var commandLineOptions  = CommandLineSwitch.Parse <CommandLineOptions>(ref args, options => options.EnumParserStyle = EnumParserStyle.OriginalCase);
            var assemblyLoader      = new CustomAssemblyLoader();
            var prerenderingOptions = BuildPrerenderingOptions(assemblyLoader, commandLineOptions);

            var crawlingResult = await PreRenderToStaticFilesAsync(commandLineOptions, assemblyLoader, prerenderingOptions);

            return(crawlingResult.HasFlag(StaticlizeCrawlingResult.HasErrors) ? 1 : 0);
        }
Esempio n. 7
0
        public void Parse_LongNameOnly_Ambiguous_Test()
        {
            var args = "http://localhost:32767 -a".Split(' ');
            var e    = Assert.Throws <InvalidCommandLineSwitchException>(() =>
            {
                var options = CommandLineSwitch.Parse <HttpServerOptions>(ref args);
            });

            e.ParserError.ErrorType.Is(ErrorTypes.UnknownOption);
        }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            var option = CommandLineSwitch.Parse <Options>(ref args);

            if (string.IsNullOrWhiteSpace(option.InputDir) ||
                string.IsNullOrWhiteSpace(option.OutputFile))
            {
                Console.WriteLine(Options.GetHelp());
                return;
            }

            Merge(option.InputDir, option.OutputFile);
        }
        static void Main(string[] args)
        {
            var options = CommandLineSwitch.Parse <CommandLineOptions>(ref args);

            options.BaseDirectory = options.BaseDirectory.Trim('"');
            if (string.IsNullOrWhiteSpace(options.BaseDirectory))
            {
                Console.WriteLine("Usage: dotnet exec Toolbelt.Blazor.TimeZoneKit.GenerateSourceCod.dll - b <base directory>");
                return;
            }

            GenerateIANAtoTZIdMap(options.BaseDirectory);
            GenerateSystemTimeZones(options.BaseDirectory);
        }
Esempio n. 10
0
        public void Parse_MissingParameter_Test()
        {
            var commandline = "--recursive --port";
            var args        = commandline.Split(' ');
            var e           = Assert.Throws <InvalidCommandLineSwitchException>(() =>
            {
                var options = CommandLineSwitch.Parse <HttpServerOptions>(ref args);
            });

            e.Message.Is("The parameter of --port is missing.");
            e.ParserError.ErrorType.Is(ErrorTypes.MissingParameter);
            e.ParserError.OptionName.Is("--port");
            e.ParserError.Parameter.IsNull();
            e.ParserError.ExpectedParameterType.Is(typeof(uint));
            args.Is(commandline.Split(' '));
        }
Esempio n. 11
0
        public void Parse_InvalidParameterFormat_Int_Test()
        {
            var commandline = "-p http://localhost/ -z";
            var args        = commandline.Split(' ');
            var e           = Assert.Throws <InvalidCommandLineSwitchException>(() =>
            {
                var options = CommandLineSwitch.Parse <HttpServerOptions>(ref args);
            });

            e.Message.Is("The parameter of -p is not an unsigned integer.");
            e.ParserError.ErrorType.Is(ErrorTypes.InvalidParameterFormat);
            e.ParserError.OptionName.Is("-p");
            e.ParserError.Parameter.Is("http://localhost/");
            e.ParserError.ExpectedParameterType.Is(typeof(uint));
            args.Is(commandline.Split(' '));
        }
Esempio n. 12
0
        public void Parse_InvalidParameterFormat_DateTime_Test()
        {
            var commandline = "-c Today -m hello";
            var args        = commandline.Split(' ');
            var e           = Assert.Throws <InvalidCommandLineSwitchException>(() =>
            {
                var options = CommandLineSwitch.Parse <VCSCommandOptions>(ref args);
            });

            e.Message.Is("The parameter of -c is not a date / time.");
            e.ParserError.ErrorType.Is(ErrorTypes.InvalidParameterFormat);
            e.ParserError.OptionName.Is("-c");
            e.ParserError.Parameter.Is("Today");
            e.ParserError.ExpectedParameterType.Is(typeof(DateTime));
            args.Is(commandline.Split(' '));
        }
Esempio n. 13
0
        public void Parse_InvalidParameterFormat_Decimal_Test()
        {
            var commandline = "-c 2017-09-14 -r Hello -z";
            var args        = commandline.Split(' ');
            var e           = Assert.Throws <InvalidCommandLineSwitchException>(() =>
            {
                var options = CommandLineSwitch.Parse <VCSCommandOptions>(ref args);
            });

            e.Message.Is("The parameter of -r is not a number.");
            e.ParserError.ErrorType.Is(ErrorTypes.InvalidParameterFormat);
            e.ParserError.OptionName.Is("-r");
            e.ParserError.Parameter.Is("Hello");
            e.ParserError.ExpectedParameterType.Is(typeof(decimal));
            args.Is(commandline.Split(' '));
        }
Esempio n. 14
0
        public void Parse_ParameterOverflow_Int_Test()
        {
            var commandline = "--port -80 -z";
            var args        = commandline.Split(' ');
            var e           = Assert.Throws <InvalidCommandLineSwitchException>(() =>
            {
                var options = CommandLineSwitch.Parse <HttpServerOptions>(ref args);
            });

            e.Message.Is("The parameter of --port is too large or too small.");
            e.ParserError.ErrorType.Is(ErrorTypes.ParameterOverflow);
            e.ParserError.OptionName.Is("--port");
            e.ParserError.Parameter.Is("-80");
            e.ParserError.ExpectedParameterType.Is(typeof(uint));
            args.Is(commandline.Split(' '));
        }
Esempio n. 15
0
        public void Parse_InvalidParameterFormat_Enum_Test()
        {
            var commandline = "-c 2017-09-14 --type Git -z";
            var args        = commandline.Split(' ');
            var e           = Assert.Throws <InvalidCommandLineSwitchException>(() =>
            {
                var options = CommandLineSwitch.Parse <VCSCommandOptions>(ref args);
            });

            e.Message.Is("The parameter of --type is not the one of git, svn.");
            e.ParserError.ErrorType.Is(ErrorTypes.InvalidParameterFormat);
            e.ParserError.OptionName.Is("--type");
            e.ParserError.Parameter.Is("Git");
            e.ParserError.ExpectedParameterType.Is(typeof(VCSTypes));
            args.Is(commandline.Split(' '));
        }
Esempio n. 16
0
        public void Parse_UnknownOption_Test()
        {
            var commandline = "-p 80 -z USWest -r -p";
            var args        = commandline.Split(' ');
            var e           = Assert.Throws <InvalidCommandLineSwitchException>(() =>
            {
                var options = CommandLineSwitch.Parse <HttpServerOptions>(ref args);
            });

            e.Message.Is("-z is unknown switch/option.");
            e.ParserError.ErrorType.Is(ErrorTypes.UnknownOption);
            e.ParserError.OptionName.Is("-z");
            e.ParserError.Parameter.IsNull();
            e.ParserError.ExpectedParameterType.IsNull();

            args.Is(commandline.Split(' '));
        }
Esempio n. 17
0
        static int Main(string[] args)
        {
            Options = CommandLineSwitch.Parse <CommandLineOptions>(ref args);

            CurrentWriter = Options.OutputMode == OutputMode.StdErr ? Console.Error : Console.Out;

            if (Options.InfiniteCounter)
            {
                InfiniteCounter();
            }
            else
            {
                HelloWorld();
            }

            if (Options.NeverExitUntilEnterAnyKey)
            {
                Console.WriteLine("Press any keys to exit.");
                Console.ReadKey(intercept: true);
            }

            return(Options.ExitCode);
        }