public void Should_Respond_To_Help_Arg()
        {
            var optionSet = new RequiredValuesOptionSet();

            //Add a non-required variable because we want to verify the help-arg.
            var name = optionSet.AddVariable<string>("n", "");

            const string HelpPrototype = "?";
            const string Description = "TESTMODE";

            var cm = new ConsoleManager("Test", optionSet, HelpPrototype, Description);

            using (var writer = new StringWriter())
            {
                var parsed = cm.TryParseOrShowHelp(writer, new[] {HelpPrototype,});

                Assert.IsFalse(parsed);

                Assert.IsTrue(writer.ToString().Contains(Description));
            }
        }
        public void Should_Respond_To_Missing_Required_VariableLists_With_Show_Help()
        {
            var optionSet = new RequiredValuesOptionSet();

            //Populate the OptionSet with some nominal options.
            var n = optionSet.AddRequiredVariableList<string>("n", "");
            var a = optionSet.AddRequiredVariableList<int>("a", "");
            var m = optionSet.AddRequiredVariableList<string>("m", "");

            const string ConsoleName = "Test";

            var cm = new ConsoleManager(ConsoleName, optionSet);

            using (var writer = new StringWriter())
            {
                var parsed = cm.TryParseOrShowHelp(writer, new string[] { });

                Assert.IsFalse(parsed);

                Assert.IsTrue(writer.ToString().Contains(ConsoleName + ": error parsing arguments:"));
            }
        }
        public void Should_Respond_To_Missing_Required_Variables_With_Show_Help()
        {
            var optionSet = new RequiredValuesOptionSet();

            //Populate the OptionSet with some nominal options.
            var name = optionSet.AddRequiredVariable <string>("n", "");
            var age  = optionSet.AddRequiredVariable <int>("a", "");
            var age2 = optionSet.AddRequiredVariable <int>("b", "");
            var age3 = optionSet.AddRequiredVariable <int>("c", "");

            const string ConsoleName = "Test";

            var cm = new ConsoleManager(ConsoleName, optionSet);

            using (var writer = new StringWriter())
            {
                var parsed = cm.TryParseOrShowHelp(writer, new string[] {});

                Assert.IsFalse(parsed);

                Assert.IsTrue(writer.ToString().Contains(ConsoleName + ": error parsing arguments:"));
            }
        }
        public void Show_Show_Help_For_Remaining_Args()
        {
            var optionSet = new RequiredValuesOptionSet();

            //This one can be a required-variable, no problem, but that's it.
            var name = optionSet.AddRequiredVariable <string>("n");

            const string ConsoleName = "Test";

            var cm = new ConsoleManager(ConsoleName, optionSet);

            //Then we should have some remaining args.
            var args = "-n ThisIsName UnknownOptionCausesErrorShowHelp".Split(' ');

            using (var writer = new StringWriter())
            {
                var parsed = cm.TryParseOrShowHelp(writer, args);

                Assert.IsFalse(parsed);

                // Test contains Visual Studio error message
                Assert.IsTrue(writer.ToString().Contains(ConsoleName + ": error parsing arguments:"));
            }
        }
        public void Show_Show_Help_For_Remaining_Args()
        {
            var optionSet = new RequiredValuesOptionSet();

            //This one can be a required-variable, no problem, but that's it.
            var name = optionSet.AddRequiredVariable<string>("n");

            const string ConsoleName = "Test";

            var cm = new ConsoleManager(ConsoleName, optionSet);

            //Then we should have some remaining args.
            var args = "-n ThisIsName UnknownOptionCausesErrorShowHelp".Split(' ');

            using (var writer = new StringWriter())
            {
                var parsed = cm.TryParseOrShowHelp(writer, args);

                Assert.IsFalse(parsed);

                // Test contains Visual Studio error message
                Assert.IsTrue(writer.ToString().Contains(ConsoleName + ": error parsing arguments:"));
            }
        }
예제 #6
0
    private static void Main(string[] args)
    {
      // TODO this code is prone to invalid inputs... idc :bikini:

      var requiredValuesOptionSet = new RequiredValuesOptionSet();
      var repository = requiredValuesOptionSet.AddRequiredVariable<string>("repository",
                                                                           "Specifies the URI to the SVN repository");
      var trunk = requiredValuesOptionSet.AddRequiredVariable<string>("trunk",
                                                                      "Specifies the relative path to the trunk, which is diffed against the <branch> parameter (usually trunk)");
      var branch = requiredValuesOptionSet.AddRequiredVariable<string>("branch",
                                                                       "Specifies the relative path to the branch, whose initial revision is used as the offset for the change log");
      var redmineHost = requiredValuesOptionSet.AddRequiredVariable<string>("redmineHost",
                                                                            "Specifies the host, which serves the Redmine instance");
      var redmineApiKey = requiredValuesOptionSet.AddRequiredVariable<string>("redmineApiKey",
                                                                              "Specifies the api key that is used for communication with the Redmine instance");
      var ignoreBranchIssues = requiredValuesOptionSet.AddVariable<bool>("ignoreBranchIssues",
                                                                         "Specifies whether issues, comitted to the branch, should be ignored or not. Default is false");
      var consoleManager = new ConsoleManager("ChangeLog Generator",
                                              requiredValuesOptionSet);
      if (!consoleManager.TryParseOrShowHelp(Console.Out,
                                             args))
      {
        return;
      }

      Console.WriteLine("Getting the initial revision of {0}",
                        branch.Value);
      var initialLogItem = Program.GetInitialLogItem(repository,
                                                     branch);
      if (initialLogItem == null)
      {
        Console.WriteLine("Could not get the initial revision of {0}",
                          branch.Value);
        return;
      }

      long[] branchIssueIds;
      if (ignoreBranchIssues)
      {
        Console.WriteLine("Getting log for {0} since {1} ({2})",
                          branch.Value,
                          initialLogItem.Revision,
                          initialLogItem.Time);
        var branchLogItems = Program.GetLogSince(repository,
                                                 branch,
                                                 initialLogItem.Revision);
        branchIssueIds = branchLogItems.SelectMany(arg => arg.GetIssueIds())
                                       .Distinct()
                                       .ToArray();
      }
      else
      {
        branchIssueIds = new long[0];
      }

      var revision = initialLogItem.ChangedPaths.Max(arg => arg.CopyFromRevision);
      Console.WriteLine("Getting log for {0} since {1}",
                        trunk.Value,
                        revision);
      var logItems = Program.GetLogSince(repository,
                                         trunk,
                                         revision);

      var complexIssueIds = logItems.SelectMany(arg => arg.GetIssueIds()
                                                          .Except(branchIssueIds)
                                                          .Select(issueId => new
                                                                             {
                                                                               LogItem = arg,
                                                                               IssueId = issueId
                                                                             }))
                                    .OrderBy(arg => arg.IssueId)
                                    .GroupBy(arg => arg.IssueId)
                                    .ToDictionary(arg => arg.Key);

      Console.WriteLine("Getting the issues for {0} since {1} ({3}) from {2}",
                        trunk.Value,
                        revision,
                        redmineHost.Value,
                        initialLogItem.Time);
      var issues = Program.GetIssues(redmineHost,
                                     redmineApiKey,
                                     complexIssueIds.Keys);

      issues.ForEach(issue =>
                     {
                       Console.WriteLine("#{0}: {1} (assigned to: {2}, commits by: {3})",
                                         issue.Id,
                                         issue.Subject,
                                         issue.AssignedTo?.Name ?? "none",
                                         string.Join(", ",
                                                     complexIssueIds[issue.Id].Select(arg => arg.LogItem)
                                                                              .Select(arg => arg.Author)
                                                                              .Distinct()));
                     });
    }