Ejemplo n.º 1
0
        public void Command_parameters_are_ordered()
        {
            // Expected parameter order:
            // - Unnamed parameters (ordered by position)
            // - Required Named parameters (ordered by name)
            // - Optional Named parameters (ordered by name)
            // - Switch parameters (ordered by name)

            var application = new SingleCommandApplicationDocumentation(name: "TestApp", "1.2.3")
            {
                Usage = new[] { "Usage line 1", "Usage line2" }
            };

            application = application
                          .WithSwitchParameter("B")
                          .WithSwitchParameter(null, "A")
                          .WithNamedParameter("paramD", required: true)
                          .WithNamedParameter("paramA", required: false)
                          .WithNamedParameter("paramC", required: true)
                          .WithNamedParameter("paramB", required: false)
                          .WithPositionalParameter(position: 2)
                          .WithPositionalParameter(position: 1);

            Approve(application);
        }
Ejemplo n.º 2
0
 public SingleCommandApplicationPage(
     DocumentSet <IDocument> documentSet,
     ICommandLineHelpPathProvider pathProvider,
     SingleCommandApplicationDocumentation model,
     CommandLineHelpConfiguration configuration)
 {
     m_DocumentSet   = documentSet ?? throw new ArgumentNullException(nameof(documentSet));
     m_PathProvider  = pathProvider ?? throw new ArgumentNullException(nameof(pathProvider));
     m_Model         = model ?? throw new ArgumentNullException(nameof(model));
     m_Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
Ejemplo n.º 3
0
        public void GetDocument_returns_expected_Markdown_for_default_settings()
        {
            var configuration = new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            var application = new SingleCommandApplicationDocumentation(name: "TestApp", "1.2.3")
            {
                Usage = new[] { "Usage line 1", "Usage line2" }
            };

            application = application.WithNamedParameter("parameter1", required: true);

            Approve(application, configuration);
        }
Ejemplo n.º 4
0
        private SingleCommandApplicationDocumentation LoadSingleCommandApplication(AssemblyDefinition assembly)
        {
            var name        = GetApplicationName(assembly);
            var version     = assembly.GetInformationalVersionOrVersion();
            var application = new SingleCommandApplicationDocumentation(name, version);

            bool IsCommandLineParameter(PropertyDefinition property)
            {
                return(property.HasAttribute(CommandLineParserTypeNames.OptionAttributeFullName) || property.HasAttribute(CommandLineParserTypeNames.ValueAttributeFullName));
            }

            // get all types with at least one property attributed as either [Option] or [Value]
            var optionTypes = assembly.MainModule
                              .GetAllTypes()
                              .Where(x => !x.IsAbstract)
                              .Where(type => type.Properties.Any(IsCommandLineParameter))
                              .ToArray();

            TypeDefinition?optionType = null;

            // no option classes found => return "empty" command (unnamed command without options or values)
            if (optionTypes.Length == 0)
            {
                m_Logger.LogWarning("No option classes found.");
            }
            // use the first option class if multiple candidates were found but log a warning
            else if (optionTypes.Length > 1)
            {
                optionType = optionTypes[0];
                var ignoredTypeNames = optionTypes.Skip(1).Select(x => x.FullName);
                m_Logger.LogWarning(
                    $"Multiple option classes found. Generating documentation for type {optionType.FullName}. " +
                    $"Ignored types: {String.Join(", ", ignoredTypeNames)}");
            }
            // single option class found
            else
            {
                optionType = optionTypes[0];
            }

            if (optionType != null)
            {
                LoadOptions(application, optionType);

                LoadValues(application, optionType);
            }



            return(application);
        }
Ejemplo n.º 5
0
        public void GetDocument_does_not_include_AutoGenerated_notice_if_the_includeAutoGeneratedNotice_setting_is_false()
        {
            var configuration = new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            configuration.Template.Default.IncludeAutoGeneratedNotice = false;

            var application = new SingleCommandApplicationDocumentation(name: "TestApp", "1.2.3")
            {
                Usage = new[] { "Usage line 1", "Usage line2" }
            };

            application = application.WithNamedParameter("parameter1", required: true);

            Approve(application, configuration);
        }
Ejemplo n.º 6
0
        public void GetDocument_returns_expected_document_02()
        {
            var configuration = new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            configuration.Template.Default.IncludeVersion = false;

            var application = new SingleCommandApplicationDocumentation(name: "TestApp", "1.2.3")
            {
                Usage = new[] { "Usage line 1", "Usage line2" }
            };

            application = application.WithNamedParameter("parameter1", required: true);

            Approve(application, configuration);
        }
Ejemplo n.º 7
0
        public void GetDocument_returns_expected_document_01()
        {
            var application = new SingleCommandApplicationDocumentation(name: "TestApp", "1.2.3")
            {
                Usage = new[] { "Usage line 1", "Usage line2" }
            };

            application = application
                          .WithNamedParameter("parameter1", required: true)
                          .WithNamedParameter("parameter2", "x", required: true)
                          .WithNamedParameter(null, "y", required: true)
                          .WithPositionalParameter(0)
                          .WithPositionalParameter(1, informationalName: "Value2", required: true)
                          .WithPositionalParameter(2, informationalName: "Value3", description: "Help text for value 3");

            Approve(application);
        }
Ejemplo n.º 8
0
        private void Approve(SingleCommandApplicationDocumentation model, CommandLineHelpConfiguration?configuration = null)
        {
            var pathProvider = new DefaultCommandLineHelpPathProvider();
            var documentSet  = new DocumentSet <IDocument>();

            configuration ??= new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            var applicationPage = new SingleCommandApplicationPage(documentSet, pathProvider, model, configuration);

            documentSet.Add(pathProvider.GetPath(model), applicationPage);

            var doc = applicationPage.GetDocument();

            Assert.NotNull(doc);
            var writer = new ApprovalTextWriter(doc.ToString());

            Approvals.Verify(writer, new ApprovalNamer(relativeOutputDirectory: "../../../_referenceResults"), Approvals.GetReporter());
        }
Ejemplo n.º 9
0
 public SingleCommandApplicationUsageSection(SingleCommandApplicationDocumentation command) : base(command)
 {
     m_Model = command ?? throw new ArgumentNullException(nameof(command));
 }