Example #1
0
        static int Main(string[] args)
        {
            Console.WriteLine("Parsing...");

            // Set up help options the way we want them.
            var helpOptions = new ArgumentSetHelpOptions()
                              .With()
                              .BlankLinesBetweenArguments(1)
                              .ShortNames(ArgumentShortNameHelpMode.IncludeWithLongName)
                              .DefaultValues(ArgumentDefaultValueHelpMode.PrependToDescription)
                              .TwoColumnLayout();

            // Wrap help options in general parsing options.
            var options = new CommandLineParserOptions {
                HelpOptions = helpOptions
            };

            // Try to parse.
            if (!CommandLineParser.TryParse(args, options, out ProgramArguments programArgs))
            {
                return(1);
            }

            Console.WriteLine("Successfully parsed.");

            return(0);
        }
        public void TestThatColumnSeparatorThrowsWithWrongLayout()
        {
            var options = new ArgumentSetHelpOptions()
                          .With().OneColumnLayout();

            options.Invoking(o => o.ColumnSeparator(" ").Apply())
            .Should().Throw <NotSupportedException>();
        }
        public void TestThatColumnWidthsThrowsWithTooManyWidths()
        {
            var options = new ArgumentSetHelpOptions()
                          .With().TwoColumnLayout();

            options.Invoking(o => o.ColumnWidths(Any.Int(), Any.Int(), Any.Int()).Apply())
            .Should().Throw <NotSupportedException>();
        }
Example #4
0
        public static ColoredMultistring GetUsageInfo(
            Type type,
            ArgumentSetHelpOptions options      = null,
            object defaultValues                = null,
            ServiceConfigurer serviceConfigurer = null)
        {
            var argSet = AttributeBasedArgumentDefinitionFactory.CreateArgumentSet(
                type,
                attribute: null,
                defaultValues: defaultValues,
                serviceConfigurer: serviceConfigurer);

            return(GetUsageInfo(argSet, options, null));
        }
Example #5
0
        /// <summary>
        /// Returns a usage string for command line argument parsing.
        /// </summary>
        /// <param name="argSet">Definition of argument set.</param>
        /// <param name="options">Options for generating usage info.</param>
        /// <param name="destination">Optionally provides an object with
        /// default values.</param>
        /// <returns>Printable string containing a user friendly description of
        /// command line arguments.</returns>
        internal static ColoredMultistring GetUsageInfo(
            ArgumentSetDefinition argSet,
            ArgumentSetHelpOptions options,
            object destination)
        {
            // Default options.
            if (options == null)
            {
                options = new ArgumentSetHelpOptions();
            }

            // Default max width.
            if (!options.MaxWidth.HasValue)
            {
                options = options.With().MaxWidth(GetCurrentConsoleWidth());
            }

            // Construct renderer.
            var renderer = new ArgumentSetHelpRenderer(options);

            // Render.
            return(renderer.Format(argSet, destination));
        }
        public void TestThatDeepCloningDefaultOptionsWorksAsExpected()
        {
            var options = new ArgumentSetHelpOptions();

            DeepCloneTests.CloneShouldYieldADistinctButEquivalentObject(options);
        }