private static int HandleError(IEnumerable <Error> errors, ParserResult <Options> parserResult)
        {
            var h = new HelpText
            {
                Heading           = "Usage: z80bench <filename[@address]> [additional files] [options]",
                AutoVersion       = false,
                AddDashesToOption = true
            };

            h.AddPreOptionsLine("Filenames will be inserted into Z80 address space at the (hex) address given, or 0 if unspecified.");
            h.AddPreOptionsLine("You should load some code at a suitable address, and end with ret. No interrupts will happen.");
            h.AddPreOptionsLine("");
            h.AddPreOptionsLine("Options:");
            h.AddOptions(parserResult);

            if (!errors.IsHelp())
            {
                h.AddPostOptionsLine("Errors:");
                h.AddPostOptionsLines(HelpText.RenderParsingErrorsTextAsLines(
                                          parserResult,
                                          error => error is MissingRequiredOptionError
                        ? "At least one filename must be given" :
                                          h.SentenceBuilder.FormatError(error),
                                          h.SentenceBuilder.FormatMutuallyExclusiveSetErrors, 2));
            }

            Console.WriteLine(h);
            return(-1);
        }
Exemplo n.º 2
0
        public static void DisplayHelp <T>(ParserResult <T> result, IEnumerable <Error> errs)
        {
            var versionString = Assembly.GetEntryAssembly()
                                .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                .InformationalVersion.ToString();

            var copyrightstring = Assembly.GetEntryAssembly()
                                  .GetCustomAttribute <AssemblyCopyrightAttribute>()
                                  .Copyright.ToString();

            HelpText helpText = HelpText.AutoBuild(result, h =>
            {
                h.Heading   = $"NuGetDownloader v{versionString}";
                h.Copyright = copyrightstring;
                h.AutoHelp  = h.AutoVersion = h.AdditionalNewLineAfterOption = false;
                return(HelpText.DefaultParsingErrorsHandler(result, h));
            }, e => e);

            if (result is DownloadCommand)
            {
                helpText.AddPostOptionsLines(DownloadHelp);
            }
            else if (result is ExtractCommand)
            {
                helpText.AddPostOptionsLines(ExtractHelp);
            }
            else if (result is VersionCommand)
            {
                helpText.AddPostOptionsLines(DisplayVersionsHelp);
            }
            else
            {
                helpText.AddPostOptionsLines(Help);
            }

            Console.WriteLine(helpText);
        }
Exemplo n.º 3
0
        public static void DisplayHelp <T>(ParserResult <T> result)
        {
            var versionString = Assembly.GetEntryAssembly()
                                .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                                .InformationalVersion.ToString();

            var copyrightstring = Assembly.GetEntryAssembly()
                                  .GetCustomAttribute <AssemblyCopyrightAttribute>()
                                  .Copyright.ToString();

            HelpText helpText = HelpText.AutoBuild(result, h =>
            {
                h.Heading   = $"JsonT v{versionString}";
                h.Copyright = copyrightstring;
                h.AutoHelp  = h.AutoVersion = h.AdditionalNewLineAfterOption = false;
                return(HelpText.DefaultParsingErrorsHandler(result, h));
            }, e => e);

            helpText.AddPostOptionsLines(Help);

            Console.WriteLine(helpText);
        }