Esempio n. 1
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);
         }
     }
 }
Esempio n. 2
0
        public string GetUsage()
        {
            var help = new HelpText
            {
                Heading = "EventStore.Client",
                AddDashesToOption = true
            };

            HandleParsingErrorsInHelp(help);
            help.AddPreOptionsLine("Usage: EventStore.Client -i 127.0.0.1 -t 1113 -h 2113");
            help.AddOptions(this);

            return help;
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new instance of the <see cref="HelpText"/> class using common defaults.
        /// </summary>
        /// <returns>
        /// An instance of <see cref="HelpText"/> class.
        /// </returns>
        /// <param name='options'>
        /// The instance that collected command line arguments parsed with <see cref="CommandLineParser"/> class.
        /// </param>
        /// <param name='errDelegate'>
        /// A delegate used to customize the text block for reporting parsing errors.
        /// </param>
        public static HelpText AutoBuild(object options, HandleParsingErrorsDelegate errDelegate)
        {
            var title = ReflectionUtil.GetAttribute<AssemblyTitleAttribute>();
            if (title == null) throw new InvalidOperationException("HelpText::AutoBuild() requires that you define AssemblyTitleAttribute.");
            var copyright = ReflectionUtil.GetAttribute<AssemblyCopyrightAttribute>();
            if (copyright == null) throw new InvalidOperationException("HelpText::AutoBuild() requires that you define AssemblyCopyrightAttribute.");
            var version = ReflectionUtil.GetAttribute<AssemblyInformationalVersionAttribute>();
            // let AssemblyInformationalVersionAttribute be null because its not added to project by default and its not so crucial

            var auto = new HelpText
            {
                Heading = new HeadingInfo(Path.GetFileNameWithoutExtension(title.Title), version != null ? version.InformationalVersion : "(unspecified)"),
                Copyright = copyright.Copyright,
                AdditionalNewLineAfterOption = true,
                AddDashesToOption = true
            };

            if (errDelegate != null)
            {
                var typedTarget = options as CommandLineOptionsBase;
                if (typedTarget != null)
                {
                    errDelegate(auto);
                }
            }

            var license = ReflectionUtil.GetAttribute<AssemblyLicenseAttribute>();
            if (license != null)
            {
                //auto.AddPreOptionsLine(license.FullText);
                license.AddToHelpText(auto, true);
            }
            var usage = ReflectionUtil.GetAttribute<AssemblyUsageAttribute>();
            if (usage != null)
            {
                //auto.AddPreOptionsLine(usage.FullText);
                usage.AddToHelpText(auto, true);
            }

            auto.AddOptions(options);

            return auto;
        }
Esempio n. 4
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); }
         }
     }
 }
Esempio n. 5
0
        /*
        public string FullText
        {
            get
            {
                if (string.IsNullOrEmpty(_fullText))
                {
                    if (!string.IsNullOrEmpty(_line1))
                    {
                        var builder = new StringBuilder(_line1);
                        builder.AppendLineIfNotNullOrEmpty(_line2);
                        builder.AppendLineIfNotNullOrEmpty(_line3);
                        builder.AppendLineIfNotNullOrEmpty(_line4);
                        builder.AppendLineIfNotNullOrEmpty(_line5);
                        _fullText = builder.ToString();
                    }
                }
                return _fullText;
            }
        }
        */

        internal void AddToHelpText(HelpText helpText, bool before)
        {
            if (before)
            {
                if (!string.IsNullOrEmpty(_line1)) helpText.AddPreOptionsLine(_line1);
                if (!string.IsNullOrEmpty(_line2)) helpText.AddPreOptionsLine(_line2);
                if (!string.IsNullOrEmpty(_line3)) helpText.AddPreOptionsLine(_line3);
                if (!string.IsNullOrEmpty(_line4)) helpText.AddPreOptionsLine(_line4);
                if (!string.IsNullOrEmpty(_line5)) helpText.AddPreOptionsLine(_line5);
            }
            else
            {
                if (!string.IsNullOrEmpty(_line1)) helpText.AddPostOptionsLine(_line1);
                if (!string.IsNullOrEmpty(_line2)) helpText.AddPostOptionsLine(_line2);
                if (!string.IsNullOrEmpty(_line3)) helpText.AddPostOptionsLine(_line3);
                if (!string.IsNullOrEmpty(_line4)) helpText.AddPostOptionsLine(_line4);
                if (!string.IsNullOrEmpty(_line5)) helpText.AddPostOptionsLine(_line5);
            }
        }