private static string GetSyntax(IEnumerable <string> actionRouteParts, OptionsHelp optionsHelp)
        {
            var appName = FileSys.Path.GetFileNameWithoutExtension(Env.GetAppFileName());

            var action = string.Join(" ", actionRouteParts);

            var arguments = string.Join(" ", optionsHelp.ValueHelpEntries.Select(x => $"[{x.ArgumentName}]"));

            var syntaxParts = new List <string> {
                appName
            };

            if (!string.IsNullOrEmpty(action))
            {
                syntaxParts.Add(action);
            }

            if (!string.IsNullOrEmpty(arguments))
            {
                syntaxParts.Add(arguments);
            }

            if (optionsHelp.ParameterHelpEntries.Any())
            {
                syntaxParts.Add("[OPTIONS]");
            }

            return(string.Join(" ", syntaxParts));
        }
Exemple #2
0
        public void CreateHelp_GivenActionViaRouter_HelpTextAndOptionsHelpCorrect()
        {
            var expectedOptionsHelp = new OptionsHelp(
                Array.Empty <HelpEntry>(),
                Array.Empty <HelpEntry>());

            var optionsHelpGenerator = A.Fake <IOptionsHelpGenerator>();

            A.CallTo(() => optionsHelpGenerator.CreateHelp(typeof(OptionsForHelp)))
            .Returns(expectedOptionsHelp);

            var actionRouter = A.Fake <ICliActionRouter>();

            A
            .CallTo(() => actionRouter.FindRoute(A <IList <string> > .Ignored))
            .Returns(
                new CliActionRoute(
                    typeof(TestControllerWithDefault),
                    typeof(TestControllerWithDefault).GetMethod(nameof(TestControllerWithDefault.Setup))
                    ?? throw new InvalidOperationException(),
                    Array.Empty <string>()));

            var helpGenerator = new CliActionHelpGenerator(optionsHelpGenerator, actionRouter);

            // Act
            var help = helpGenerator.CreateHelp(new [] { "test" });

            // Assert
            help.HelpText
            .Should()
            .Be("Setups the config");

            help.OptionsHelp
            .Should()
            .Be(expectedOptionsHelp);

            A.CallTo(() => optionsHelpGenerator.CreateHelp(typeof(OptionsForHelp)))
            .MustHaveHappenedOnceExactly();
        }
Exemple #3
0
 public CliActionHelp(OptionsHelp optionsHelp)
 {
     OptionsHelp = optionsHelp;
 }