示例#1
0
        /// <summary>
        /// Supplies a default parsing error handler implementation.
        /// </summary>
        /// <param name="options">The instance that collects parsed arguments parsed and associates <see cref="CommandLine.ParserStateAttribute"/>
        /// to a property of type <see cref="IParserState"/>.</param>
        /// <param name="current">The <see cref="CommandLine.Text.HelpText"/> instance.</param>
        public static void DefaultParsingErrorsHandler(object options, HelpText current)
        {
            var list = ReflectionHelper.RetrievePropertyList <ParserStateAttribute>(options);

            if (list.Count == 0)
            {
                return;
            }

            var parserState = (IParserState)list[0].Left.GetValue(options, null);

            if (parserState == null || parserState.Errors.Count == 0)
            {
                return;
            }

            var errors = current.RenderParsingErrorsText(options, 2); // indent with two spaces

            if (!string.IsNullOrEmpty(errors))
            {
                current.AddPreOptionsLine(string.Concat(Environment.NewLine, current.SentenceBuilder.ErrorsHeadingText));
                var lines = errors.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                foreach (var line in lines)
                {
                    current.AddPreOptionsLine(line);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Supplies a default parsing error handler implementation.
        /// </summary>
        /// <param name='parserResult'>The <see cref="CommandLine.ParserResult{T}"/> containing the instance that collected command line arguments parsed with <see cref="CommandLine.Parser"/> class.</param>
        /// <param name="current">The <see cref="CommandLine.Text.HelpText"/> instance.</param>
        public static HelpText DefaultParsingErrorsHandler <T>(ParserResult <T> parserResult, HelpText current)
        {
            if (parserResult == null)
            {
                throw new ArgumentNullException("parserResult");
            }
            if (current == null)
            {
                throw new ArgumentNullException("current");
            }

            if (FilterMeaningfulErrors(parserResult.Errors).Empty())
            {
                return(current);
            }

            var errors = HelpText.RenderParsingErrorsText(parserResult, current.SentenceBuilder.FormatError, 2); // indent with two spaces

            if (string.IsNullOrEmpty(errors))
            {
                return(current);
            }

            current.AddPreOptionsLine(string.Concat(Environment.NewLine, current.SentenceBuilder.ErrorsHeadingText()));
            var lines = errors.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            foreach (var line in lines)
            {
                current.AddPreOptionsLine(line);
            }

            return(current);
        }
示例#3
0
        public string GetUsage()
        {
            var name = Assembly.GetExecutingAssembly().GetName();
            var help = new HelpText
            {
                Heading = new HeadingInfo(name.Name, name.Version.ToString()),
                Copyright = new CopyrightInfo("me!", 2015),
                AdditionalNewLineAfterOption = true,
                AddDashesToOption = true
            };

            if (LastParserState.Errors.Any())
            {
                var errors = help.RenderParsingErrorsText(this, 2);
                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR(S):"));
                    help.AddPreOptionsLine(errors);
                }
            }

            help.AddPreOptionsLine("Usage: RunMongoRun [options]");
            help.AddOptions(this);
            return help;
        }
        public string GetUsage()
        {
            string processname = Process.GetCurrentProcess().ProcessName;

            var help = new HelpText
            {
                AdditionalNewLineAfterOption = false,
                AddDashesToOption = true,
                Copyright = new CopyrightInfo("Geoffrey Huntley <*****@*****.**>", DateTime.Now.Year),
                MaximumDisplayWidth = 160,
            };

            help.AddPreOptionsLine(Environment.NewLine);
            help.AddPreOptionsLine(
                String.Format(
                    "Usage: {0} --destination C:\\backups\\ --sleep 600 --instance https://yourinstance.atlassian.net --username admin --password password",
                    processname));

            help.AddOptions(this);

            if (LastParserState.Errors.Count <= 0) return help;

            string errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces
            if (!string.IsNullOrEmpty(errors))
            {
                help.AddPostOptionsLine(Environment.NewLine);
                help.AddPostOptionsLine("ERROR(s):");help.AddPostOptionsLine(Environment.NewLine);
                help.AddPostOptionsLine(errors);
            }

            return help;
        }
示例#5
0
        public string GetUsage()
        {
            var help = new HelpText
            {
                Heading = new HeadingInfo("#b#Versionr## #q#- the less hateful version control system.##"),
                AddDashesToOption = true,
            };
            help.FormatOptionHelpText += Help_FormatOptionHelpText;

            // ...
            if (LastParserState != null && LastParserState.Errors.Any())
            {
                var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces

                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(string.Concat(Environment.NewLine, "Invalid command:"));
                    help.AddPreOptionsLine(errors);
                }
            }
            help.AddPreOptionsLine(string.Format("\nUsage:\n   {0}\n", Usage));
            help.AddPreOptionsLine(string.Format("##The `#b#{0}##` Command:", Verb));
            foreach (var x in Description)
                help.AddPreOptionsLine("  " + x);
            help.AddPreOptionsLine("\n##Options:#b#");
            help.AddOptions(this);
            return help;
        }
示例#6
0
        public string GetUsage()
        {
            var help = new HelpText
            {
                Heading = new HeadingInfo("CqlSharp.Performance.Client", "0.1.0"),
                Copyright = new CopyrightInfo("Joost Reuzel", 2014),
                AdditionalNewLineAfterOption = true,
                AddDashesToOption = true
            };

            if(LastParserState.Errors.Any())
            {
                var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces

                if(!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR(S):"));
                    help.AddPreOptionsLine(errors);
                }
            }

            help.AddPreOptionsLine("Usage: Client -c 100 -r 10000");
            help.AddOptions(this);
            return help;
        }
示例#7
0
 private void HandleParsingErrorsInHelp(HelpText help)
 {
     string errors = help.RenderParsingErrorsText(this);
     if (!string.IsNullOrEmpty(errors))
     {
         help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR: ", errors, Environment.NewLine));
     }
 }
示例#8
0
 private void HandleParsingErrorsInHelp(HelpText help)
 {
     if (LastParserState != null && LastParserState.Errors.Any()) {
         var errors = help.RenderParsingErrorsText(this, 2);
         if (!string.IsNullOrEmpty(errors)) {
             help.AddPreOptionsLine(Environment.NewLine + "Error(s):");
             help.AddPreOptionsLine(errors);
         }
     }
 }
        public string GetUsage()
        {
            var asm = Assembly.GetExecutingAssembly();

            var productName =
                asm.GetCustomAttributes(typeof (AssemblyTitleAttribute), false)
                    .OfType<AssemblyTitleAttribute>()
                    .Single()
                    .Title;
            var productVersion =
                asm.GetCustomAttributes(typeof (AssemblyInformationalVersionAttribute), false)
                    .OfType<AssemblyInformationalVersionAttribute>()
                    .Single()
                    .InformationalVersion;
            var productCopyright =
                asm.GetCustomAttributes(typeof (AssemblyCopyrightAttribute), false)
                    .OfType<AssemblyCopyrightAttribute>()
                    .Single()
                    .Copyright;

            var help = new HelpText
            {
                AddDashesToOption = true,
                AdditionalNewLineAfterOption = true,
                Copyright = productCopyright,
                Heading = new HeadingInfo(productName, productVersion),
                MaximumDisplayWidth = Console.BufferWidth
            };

            var errors = help.RenderParsingErrorsText(this, 2);
            if (!string.IsNullOrEmpty(errors))
            {
                help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR(S):"));
                help.AddPreOptionsLine(errors);
            }

            help.AddPreOptionsLine(" ");
#if !NO_COMMANDLINE
            help.AddPreOptionsLine(((AssemblyLicenseAttribute)assembly
                .GetCustomAttributes(typeof(AssemblyLicenseAttribute), false)
                .Single()).Value.Trim());
#else
            help.AddPreOptionsLine(
                "This is free software. You may redistribute copies of it under the terms of the MIT License <http://www.opensource.org/licenses/mit-license.php>.");
#endif
            help.AddPreOptionsLine(" ");
            help.AddPreOptionsLine(string.Format("{0} [options...] \"<targetpath>\"",
                Process.GetCurrentProcess().ProcessName));

            help.AddOptions(this);

            return help.ToString();
        }
示例#10
0
 private void HandleParsingErrorsInHelp(HelpText help)
 {
     if (this.LastPostParsingState.Errors.Count > 0)
     {
         var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces
         if (!string.IsNullOrEmpty(errors))
         {
             help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR(S):"));
             help.AddPreOptionsLine(errors);
         }
     }
 }
        public string GetUsage()
        {
            var help = new HelpText();

            if (this.LastParserState.Errors.Any())
            {
                var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces
                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR(S):"));
                    help.AddPreOptionsLine(errors);
                }
            }
            return help;
        }
示例#12
0
        /// <summary>
        /// message of errors
        /// </summary>
        /// <returns>string of message of errors</returns>
        public string GetUsageError()
        {
            var help = new HelpText();
                if (this.LastParserState.Errors.Count > 0)
                {
                    var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces
                    if (!string.IsNullOrEmpty(errors))
                    {
                        help.AddPreOptionsLine(string.Concat("\n", "Error(s):"));
                        help.AddPreOptionsLine(errors);
                    }
                }

                return help;
        }
        public string GetUsageHelp()
        {
            var help = new HelpText
            {
                Heading = GetProductName(),
                Copyright = GetProductCopyright(),
                AddDashesToOption = true,
                AdditionalNewLineAfterOption = true,
                MaximumDisplayWidth = 75,
            };

            help.RenderParsingErrorsText(this, 0);
            help.AddOptions(this);

            return help;
        }
示例#14
0
文件: Options.cs 项目: Knoema/shp2svg
        public string Errors()
        {
            var help = new HelpText();

            if (this.LastPostParsingState.Errors.Count > 0)
            {
                var errors = help.RenderParsingErrorsText(this, 2);
                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR(S):"));
                    help.AddPreOptionsLine(errors);
                }
            }

            return help;
        }
示例#15
0
 public string GetUsage()
 {
     var help = new HelpText("GeoIp Example runner", "Copyright 2013", this);
     // ...
     if (this.LastParserState.Errors.Count > 0)
     {
         var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces
         if (!string.IsNullOrEmpty(errors))
         {
             help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR(S):"));
             help.AddPreOptionsLine(errors);
         }
     }
     // ...
     return help.ToString();
 }
示例#16
0
 public static void DefaultParsingErrorsHandler(CommandLineOptionsBase options, HelpText current)
 {
     if (options.InternalLastPostParsingState.Errors.Count > 0)
     {
         var errors = current.RenderParsingErrorsText(options, 2); // indent with two spaces
         if (!string.IsNullOrEmpty(errors))
         {
             current.AddPreOptionsLine(string.Concat(Environment.NewLine, current.SentenceBuilder.ErrorsHeadingText));
             //current.AddPreOptionsLine(errors);
             var lines = errors.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
             foreach (var line in lines)
             {
                 current.AddPreOptionsLine(line);
             }
         }
     }
 }
        public string GetUsage()
        {
            var help = new HelpText();

            if (Help)
            {
                help.AddPreOptionsLine("Generate docx document from template and data entity");
                help.AddOptions(this);
            }
            else if (ParserState != null && ParserState.Errors.Any())
            {
                help.AddPreOptionsLine("ERROR(S):");
                help.AddPreOptionsLine(help.RenderParsingErrorsText(this, 2));
                help.AddPreOptionsLine("use key -h/--help for help");
            }

            return help;
        }
示例#18
0
        public string GetUsage()
        {
            var help = new HelpText { AddDashesToOption = true };
            if (this.LastParserState != null && this.LastParserState.Errors.Any())
            {
                var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces
                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine("ERROR(S):");
                    help.AddPreOptionsLine(errors);
                }
            }

            help.AddPreOptionsLine("Usage: acbuilder [OPTIONS] assetcatalog");
            help.AddOptions(this);

            return help;
        }
示例#19
0
        public string Usage()
        {
            var help = new HelpText
            {
                Heading = new HeadingInfo("DependencyGraphCLI", "1.0"),
                Copyright = new CopyrightInfo("Marc Carré", 2016),
                AdditionalNewLineAfterOption = true,
                AddDashesToOption = true
            };

            var errors = help.RenderParsingErrorsText(this, NumSpaces);
            if (!string.IsNullOrEmpty(errors))
            {
                help.AddPreOptionsLine(string.Concat(Environment.NewLine, "[ERROR(S)]:"));
                help.AddPreOptionsLine(errors);
            }

            help.AddPreOptionsLine("License: Apache License, Version 2.0");
            help.AddPreOptionsLine("Usage: DependencyGraphCLI -a/--assemblies [FILE]...");
            help.AddOptions(this);
            return help;
        }
示例#20
0
        public string GetUsage()
        {
            var help = new HelpText
            {
                Heading = new HeadingInfo("#b#Logr## #q#- Retrieves Versionr logs and updates continuous integration status.##"),
                AddDashesToOption = true,
            };
            help.FormatOptionHelpText += Help_FormatOptionHelpText;

            // ...
            if (LastParserState != null && LastParserState.Errors.Any())
            {
                var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces

                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(string.Concat(Environment.NewLine, "Invalid command:"));
                    help.AddPreOptionsLine(errors);
                }
            }
            help.AddPreOptionsLine("Usage: #b#logr## -r repo -l logfile #q#[options]## \n\n#b#Options:");
            help.AddOptions(this);
            return help;
        }
示例#21
0
        public string GetUsage()
        {
            var help = new HelpText
            {
                Copyright = new CopyrightInfo("Info-Assure", 2015),
                AdditionalNewLineAfterOption = false,
                AddDashesToOption = true
            };

            help.AddPreOptionsLine("Usage: dumpntds -m p -n ntds.dit");
            help.AddOptions(this);

            if( this.LastParserState != null)
            {
                var errors = help.RenderParsingErrorsText(this, 0); // indent with two spaces
                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR(S):"));
                    help.AddPreOptionsLine(errors);
                }
            }

            return help;
        }
示例#22
0
        public string GetUsage()
        {
            var help = new HelpText
            {
                Heading = new HeadingInfo("URL Benchmark Client", "v.01"),
                Copyright = new CopyrightInfo("Jan Auer, Manuel Gerding, Philip Schäfer", 2013),
                AdditionalNewLineAfterOption = true,
                AddDashesToOption = true
            };
            help.AddPreOptionsLine("Licensed under MIT License.");
            help.AddOptions(this);

            if (LastParserState.Errors.Count > 0)
            {
                var errors = help.RenderParsingErrorsText(this, 2);
                if (!String.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(String.Concat(Environment.NewLine, "ERROR(S):"));
                    help.AddPreOptionsLine(errors);
                }
            }

            return help;
        }
示例#23
0
        static void Main(string[] args)
        {

            JsonConvert.DefaultSettings = () =>
            {
                var settings = new JsonSerializerSettings();
                settings.Formatting = Formatting.Indented;
                settings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
                settings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());

                return settings;
            };


            var options = new CommandOptions();
            
            


            string verbName = "";
            object verbOptions = null;

            if (!CommandLine.Parser.Default.ParseArguments(args, options, (verb, obj) =>
                {
                    verbName = verb;
                    verbOptions = obj;
                }))
            {
                Console.WriteLine("Failed to parse console args");

                HelpText text = new HelpText();
                
                if(options.BuilderOptions != null)
                {
                    Console.WriteLine(text.RenderParsingErrorsText(options.BuilderOptions, 1));
                }

                if (options.UpdaterOptions != null)
                {
                    Console.WriteLine(text.RenderParsingErrorsText(options.UpdaterOptions, 1));
                }

                Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
            }

            if (verbName == "createBuild")
            {
                BuilderOptions op = verbOptions as BuilderOptions;

                CreateBuild(op);
            }
            else if (verbName == "update")
            {
                UpdaterOptions op = verbOptions as UpdaterOptions;

                DownloadLatestVersion(op);
            }

        }
示例#24
0
            public string GetUsage()
            {
                var help = new HelpText(new HeadingInfo("unittest", "1.9"));
                help.AdditionalNewLineAfterOption = true;
                help.Copyright = new CopyrightInfo("CommandLine.dll Author", 2005, 2011);

                // handling parsing error code
                string errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces
                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(string.Concat(Environment.NewLine, "ERROR(S):"));
                    help.AddPreOptionsLine(errors);
                }

                help.AddPreOptionsLine("This is free software. You may redistribute copies of it under the terms of");
                help.AddPreOptionsLine("the MIT License <http://www.opensource.org/licenses/mit-license.php>.");
                help.AddPreOptionsLine("Usage: Please run the unit...");
                help.AddOptions(this);

                return help;
            }
示例#25
0
        public string GetUsage()
        {
            var help = new HelpText
            {
                Heading = new HeadingInfo("#b#Versionr## #q#- the less hateful version control system.##"),
                AddDashesToOption = false,
            };
            help.FormatOptionHelpText += Help_FormatOptionHelpText;

            // ...
            if (LastParserState != null && LastParserState.Errors.Any())
            {
                var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces

                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine(string.Concat(Environment.NewLine, "Invalid command:"));
                    help.AddPreOptionsLine(errors);
                }
            }
            help.AddPreOptionsLine("Usage: #b#versionr## COMMAND #q#[options]## <arguments>\n\n#b#Commands:");
            help.AddOptions(this);
            help.AddPostOptionsLine("##For additional help, use: #b#versionr## COMMAND #b#--help##.");
            help.AddPostOptionsLine("To display version information, use the `#b#--version##` option.\n");
            return help;
        }
 public virtual void ParseErrors(HelpText builder)
 {
     if (State != null && State.Errors != null)
     {
         if (State.Errors.Count > 0)
         {
             var errors = builder.RenderParsingErrorsText(this, 2);
             if (!string.IsNullOrEmpty(errors))
             {
                 builder.AddPreOptionsLine(
                     string.Concat(Environment.NewLine, ErrorDetailText, Environment.NewLine));
                 builder.AddPreOptionsLine(errors);
             }
         }
     }
 }
示例#27
0
        static void Main(string[] args)
        {
            try
            {
                var options = new ConsoleOptions();
                if (!Parser.Default.ParseArguments(args, options) || options.ShowHelp == true)
                {
                    if (options.LastParserState != null && options.LastParserState.Errors.Count > 0)
                    {
                        var help = new HelpText();
                        var errors = help.RenderParsingErrorsText(options, 2); // indent with two spaces
                        Console.WriteLine("Jackett v" + Engine.ConfigService.GetVersion());
                        Console.WriteLine("Switch error: " + errors);
                        Console.WriteLine("See --help for further details on switches.");
                        Environment.ExitCode = 1;
                        return;
                    }
                    else
                    {

                        var text = HelpText.AutoBuild(options, (HelpText current) => HelpText.DefaultParsingErrorsHandler(options, current));
                        text.Copyright = " ";
                        text.Heading = "Jackett v" + Engine.ConfigService.GetVersion() + " options:";
                        Console.WriteLine(text);
                        Environment.ExitCode = 1;
                        return;
                    }
                }
                else
                {

                    if (options.ListenPublic && options.ListenPrivate)
                    {
                        Console.WriteLine("You can only use listen private OR listen publicly.");
                        Environment.ExitCode = 1;
                        return;
                    }
                    /*  ======     Options    =====  */

                    // SSL Fix
                    Startup.DoSSLFix = options.SSLFix;

                    // Use curl
                    if (options.Client != null)
                        Startup.ClientOverride = options.Client.ToLowerInvariant();

                    // Use Proxy
                    if (options.ProxyConnection != null)
                    {
                        Startup.ProxyConnection = options.ProxyConnection.ToLowerInvariant();
                        Engine.Logger.Info("Proxy enabled. " + Startup.ProxyConnection);
                    }
                    // Logging
                    if (options.Logging)
                        Startup.LogRequests = true;

                    // Tracing
                    if (options.Tracing)
                        Startup.TracingEnabled = true;

                    // Log after the fact as using the logger will cause the options above to be used

                    if (options.Logging)
                        Engine.Logger.Info("Logging enabled.");

                    if (options.Tracing)
                        Engine.Logger.Info("Tracing enabled.");

                    if (options.SSLFix == true)
                        Engine.Logger.Info("SSL ECC workaround enabled.");
                    else if (options.SSLFix == false)
                        Engine.Logger.Info("SSL ECC workaround has been disabled.");

                    // Ignore SSL errors on Curl
                    Startup.IgnoreSslErrors = options.IgnoreSslErrors;
                    if (options.IgnoreSslErrors == true)
                    {
                        Engine.Logger.Info("Curl will ignore SSL certificate errors.");
                    }

                    // Choose Data Folder
                    if (!string.IsNullOrWhiteSpace(options.DataFolder))
                    {
                        Startup.CustomDataFolder = options.DataFolder.Replace("\"", string.Empty).Replace("'", string.Empty).Replace(@"\\", @"\");
                        Engine.Logger.Info("Jackett Data will be stored in: " + Startup.CustomDataFolder);
                    }

                    /*  ======     Actions    =====  */

                    // Install service
                    if (options.Install)
                    {
                        Engine.ServiceConfig.Install();
                        return;
                    }

                    // Uninstall service
                    if (options.Uninstall)
                    {
                        Engine.Server.ReserveUrls(doInstall: false);
                        Engine.ServiceConfig.Uninstall();
                        return;
                    }

                    // Reserve urls
                    if (options.ReserveUrls)
                    {
                        Engine.Server.ReserveUrls(doInstall: true);
                        return;
                    }

                    // Start Service
                    if (options.StartService)
                    {
                        if (!Engine.ServiceConfig.ServiceRunning())
                        {
                            Engine.ServiceConfig.Start();
                        }
                        return;
                    }

                    // Stop Service
                    if (options.StopService)
                    {
                        if (Engine.ServiceConfig.ServiceRunning())
                        {
                            Engine.ServiceConfig.Stop();
                        }
                        return;
                    }

                    // Migrate settings
                    if (options.MigrateSettings)
                    {
                        Engine.ConfigService.PerformMigration();
                        return;
                    }


                    // Show Version
                    if (options.ShowVersion)
                    {
                        Console.WriteLine("Jackett v" + Engine.ConfigService.GetVersion());
                        return;
                    }

                    /*  ======     Overrides    =====  */

                    // Override listen public
                    if (options.ListenPublic || options.ListenPrivate)
                    {
                        if (Engine.Server.Config.AllowExternal != options.ListenPublic)
                        {
                            Engine.Logger.Info("Overriding external access to " + options.ListenPublic);
                            Engine.Server.Config.AllowExternal = options.ListenPublic;
                            if (System.Environment.OSVersion.Platform != PlatformID.Unix)
                            {
                                if (ServerUtil.IsUserAdministrator())
                                {
                                    Engine.Server.ReserveUrls(doInstall: true);
                                }
                                else
                                {
                                    Engine.Logger.Error("Unable to switch to public listening without admin rights.");
                                    Environment.ExitCode = 1;
                                    return;
                                }
                            }

                            Engine.Server.SaveConfig();
                        }
                    }

                    // Override port
                    if (options.Port != 0)
                    {
                        if (Engine.Server.Config.Port != options.Port)
                        {
                            Engine.Logger.Info("Overriding port to " + options.Port);
                            Engine.Server.Config.Port = options.Port;
                            if (System.Environment.OSVersion.Platform != PlatformID.Unix)
                            {
                                if (ServerUtil.IsUserAdministrator())
                                {
                                    Engine.Server.ReserveUrls(doInstall: true);
                                }
                                else
                                {
                                    Engine.Logger.Error("Unable to switch ports when not running as administrator");
                                    Environment.ExitCode = 1;
                                    return;
                                }
                            }

                            Engine.Server.SaveConfig();
                        }
                    }
                }

                Engine.Server.Initalize();
                Engine.Server.Start();
                Engine.RunTime.Spin();
                Engine.Logger.Info("Server thread exit");
            }
            catch (Exception e)
            {
                Engine.Logger.Error(e, "Top level exception");
            }
        }
示例#28
0
        public string GetUsage()
        {
            // --------------------------------------------------
            // Initializes the HelpText object
            // --------------------------------------------------
            var help = new HelpText
            {
                AdditionalNewLineAfterOption = true,
                AddDashesToOption = true
            };

            help.AddPreOptionsLine(string.Format("  PNP.Deployer (v.{0}) - By Simon-Pierre Plante", Assembly.GetExecutingAssembly().GetName().Version.ToString()));
            help.AddPreOptionsLine("");
            help.AddPreOptionsLine("");

            // --------------------------------------------------
            // Adds the error section if any
            // --------------------------------------------------
            if (this.LastParserState != null && this.LastParserState.Errors.Count > 0 )
            {

                var errors = help.RenderParsingErrorsText(this, 4);

                if (!string.IsNullOrEmpty(errors))
                {
                    help.AddPreOptionsLine("  Error(s):");
                    help.AddPreOptionsLine("");
                    help.AddPreOptionsLine(errors);
                    help.AddPreOptionsLine("");
                }
            }

            // --------------------------------------------------
            // Adds the Usage section
            // --------------------------------------------------
            help.AddPreOptionsLine("  Usage:");
            help.AddPreOptionsLine("");
            help.AddPreOptionsLine("    PNP.Deployer.exe --WorkingDirectory \"C:\\DeploymentFolder\"");
            help.AddPreOptionsLine("                     [--PromptCredentials] [--Environment \"OnPrem|Online\"]");
            help.AddPreOptionsLine("");
            help.AddPreOptionsLine("");

            // --------------------------------------------------
            // Adds the Options section
            // --------------------------------------------------
            help.AddPreOptionsLine("  Options: ");
            help.AddOptions(this);

            return help;
        }
示例#29
0
 /// <summary>
 /// Supplies a default parsing error handler implementation.
 /// </summary>
 /// <param name="options">The instance that collects parsed arguments parsed and associates <see cref="CommandLine.ParserStateAttribute"/>
 /// to a property of type <see cref="IParserState"/>.</param>
 /// <param name="current">The <see cref="CommandLine.Text.HelpText"/> instance.</param>
 public static void DefaultParsingErrorsHandler(object options, HelpText current)
 {
     var list = ReflectionUtil.RetrievePropertyList<ParserStateAttribute>(options);
     if (list.Count == 0)
     {
         return;
     }
     var parserState = (IParserState) list[0].Left.GetValue(options, null);
     if (parserState == null || parserState.Errors.Count == 0)
     {
         return;
     }
     var errors = current.RenderParsingErrorsText(options, 2); // indent with two spaces
     if (!string.IsNullOrEmpty(errors))
     {
         current.AddPreOptionsLine(string.Concat(Environment.NewLine, current.SentenceBuilder.ErrorsHeadingText));
         var lines = errors.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
         foreach (var line in lines)
         {
             current.AddPreOptionsLine(line);
         }
     }
 }
 public static void DefaultParsingErrorsHandler(CommandLineOptionsBase options, HelpText current)
 {
     if (options.InternalLastPostParsingState.Errors.Count > 0)
     {
         var errors = current.RenderParsingErrorsText(options, 2); // indent with two spaces
         if (!string.IsNullOrEmpty(errors))
         {
             current.AddPreOptionsLine(string.Concat(Environment.NewLine, current.SentenceBuilder.ErrorsHeadingText));
             //current.AddPreOptionsLine(errors);
             var lines = errors.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
             foreach (var line in lines) { current.AddPreOptionsLine(line); }
         }
     }
 }