diff --git a/Program.cs b/Program.cs index d93bbc9..4e839b2 100644 --- a/Program.cs +++ b/Program.cs @@ -16,13 +16,20 @@ static class Program ); branchOption.AddAlias("-b"); + var tagOption = new Option( + "--tag", + "Specify the tag to filter by" + ); + tagOption.AddAlias("-t"); + var rootCommand = new RootCommand("Get a tally of contributors' commits") { outputOption, branchOption, + tagOption, }; - rootCommand.SetHandler((outputOptionValue, branchOptionValue) => { + rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue) => { CommitDetail commits = new CommitDetail(); switch (outputOptionValue) @@ -31,48 +38,78 @@ static class Program StdOutDataService outDataService = new StdOutDataService(); DataAccess dataAccess = new DataAccess(outDataService); - switch (branchOptionValue) - { - case null: - commits.GetCurrentCommitsByName(); - dataAccess.WriteData(commits.CommitDetails); - break; - default: - commits.GetCommitsByBranch(branchOptionValue); - dataAccess.WriteData(commits.CommitDetails); - break; + if (branchOptionValue != null && tagOptionValue != null) { + Console.WriteLine("Please specify either a branch or a tag"); + Environment.Exit(2); + } else if (branchOptionValue != null && tagOptionValue == null) { + switch (branchOptionValue) + { + case null: + commits.GetCurrentCommitsByName(); + dataAccess.WriteData(commits.CommitDetails); + break; + default: + commits.GetCommitsByBranch(branchOptionValue); + dataAccess.WriteData(commits.CommitDetails); + break; + } + break; + } else if (branchOptionValue == null && tagOptionValue != null) { + commits.GetCommitsByTag(tagOptionValue); + dataAccess.WriteData(commits.CommitDetails); } break; case "xlsx": ExcelDataService excelDataService = new ExcelDataService(); DataAccess dataAccessExcelCase = new DataAccess(excelDataService); - switch (branchOptionValue) - { - case null: - commits.GetCurrentCommitsByName(); - dataAccessExcelCase.WriteData(commits.CommitDetails); - break; - default: - commits.GetCommitsByBranch(branchOptionValue); - dataAccessExcelCase.WriteData(commits.CommitDetails); - break; + if (branchOptionValue != null && tagOptionValue != null) { + Console.WriteLine("Please specify either a branch or a tag."); + Environment.Exit(2); + } else if (branchOptionValue != null && tagOptionValue == null) { + switch (branchOptionValue) + { + case null: + commits.GetCurrentCommitsByName(); + dataAccessExcelCase.WriteData(commits.CommitDetails); + break; + default: + commits.GetCommitsByBranch(branchOptionValue); + dataAccessExcelCase.WriteData(commits.CommitDetails); + break; + } + break; + } else if (branchOptionValue == null && tagOptionValue != null) { + commits.GetCommitsByTag(tagOptionValue); + dataAccessExcelCase.WriteData(commits.CommitDetails); } break; case null: StdOutDataService stdOutDataService = new StdOutDataService(); DataAccess dataAccessNullCase = new DataAccess(stdOutDataService); - switch (branchOptionValue) - { - case null: - commits.GetCurrentCommitsByName(); - dataAccessNullCase.WriteData(commits.CommitDetails); - break; - default: - commits.GetCommitsByBranch(branchOptionValue); - dataAccessNullCase.WriteData(commits.CommitDetails); - break; + if (branchOptionValue != null && tagOptionValue != null) { + Console.WriteLine("Please specify either a branch or a tag."); + Environment.Exit(2); + } else if (branchOptionValue != null && tagOptionValue == null) { + switch (branchOptionValue) + { + case null: + commits.GetCurrentCommitsByName(); + dataAccessNullCase.WriteData(commits.CommitDetails); + break; + default: + commits.GetCommitsByBranch(branchOptionValue); + dataAccessNullCase.WriteData(commits.CommitDetails); + break; + } + break; + } else if (branchOptionValue == null && tagOptionValue != null) { + commits.GetCommitsByTag(tagOptionValue); + dataAccessNullCase.WriteData(commits.CommitDetails); + } else { + commits.GetCurrentCommitsByName(); + dataAccessNullCase.WriteData(commits.CommitDetails); } break; default: @@ -81,7 +118,7 @@ static class Program break; } }, - outputOption, branchOption); + outputOption, branchOption, tagOption); rootCommand.Invoke(args); }