Esempio n. 1
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. 2
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;
        }