Exemplo n.º 1
0
        public string GetUsage(ICommandLineOptionMode[] availableModes)
        {
            var helpText = new HelpText
            {
                AddDashesToOption = true
            };
            var usageLines = availableModes.Select(mode => $"ReportUnit {mode.Usage()} <options>");

            helpText.AddPreOptionsLines(usageLines);
            helpText.AddOptions(this);
            return(helpText);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Displays the help usage, possibly with some error messages, and then exits (non-zero).
        /// </summary>
        /// <param name="parserResult">The results from a CommandLine.Parser.ParseArguments() operation.</param>
        /// <param name="errors">An errors reported by the parserResult.</param>
        /// <param name="msg">An optional error message to accompany the output.</param>
        private static void ShowUsageHelp <T>(ParserResult <T> parserResult, IEnumerable <Error> errors = null, string msg = null)
        {
            if (msg != null)
            {
                Console.Error.WriteLine(msg);
                Console.Error.WriteLine();
            }

            if (errors == null)
            {
                errors = new List <Error>();
            }

            HelpText helpText = null;

            if (errors.IsVersion())
            {
                helpText = HelpText.AutoBuild(parserResult);
            }
            else
            {
                helpText = HelpText.AutoBuild(
                    parserResult,
                    onError: ht =>
                {
                    return(HelpText.DefaultParsingErrorsHandler(parserResult, ht));
                },
                    e => e);
                helpText.AddNewLineBetweenHelpSections = true;
                helpText.AddPreOptionsLines(new[]
                {
                    string.Empty,

                    // Use a single long line of text to let the help output get wrapped automatically for us.
                    "The Mlos.Agent.Server acts as an external agent for MLOS integrated components, allowing them to "
                    + "send it messages over shared memory, which it can process and use to interface with an optimizer "
                    + "service to tune the components over their shared memory communication channels.",
                    string.Empty,

                    // Indent the actual commands to make them stand out a bit more.
                    // Note: The help out preserves the indent across wrapping.
                    "usage mode 1:  Wait for an application to register over global shared memory, without an optimizer.",
                    "    dotnet Mlos.Agent.Server.dll",
                    string.Empty,

                    "usage mode 2:  Wait for an application to register over global shared memory, and prepare to "
                    + "communicate with an MLOS optimizer listening at the given Grpc URI.",
                    "    dotnet Mlos.Agent.Server.dll --optimizer-uri http://localhost:50051",
                    string.Empty,

                    "usage mode 3:  Start an executable to communicate over freshly prepared global shared memory.",
                    "    dotnet Mlos.Agent.Server.dll --executable path/to/executable",
                    string.Empty,

                    "usage mode 4:  Start an executable to communicate over freshly prepared global shared memory and "
                    + "prepare to communicate with an MLOS optimizer listening at the given Grpc URI.",
                    "    dotnet Mlos.Agent.Server.dll --executable path/to/executable --optimizer-uri http://localhost:50051",
                    string.Empty,

                    "Note: the optimizer service used in these examples can be started using the 'start_optimizer_microservice "
                    + "launch --port 50051' command from the mlos Python module.",
                });
            }

            Console.WriteLine(helpText);
            Environment.Exit(1);
        }