added command line arg for tag filtering, added arg logic for tag filtering

This commit is contained in:
Wyatt J. Miller 2022-08-23 18:57:18 -04:00
parent e4d8e3f66e
commit 7721031d62

View File

@ -16,13 +16,20 @@ static class Program
); );
branchOption.AddAlias("-b"); branchOption.AddAlias("-b");
var tagOption = new Option<string>(
"--tag",
"Specify the tag to filter by"
);
tagOption.AddAlias("-t");
var rootCommand = new RootCommand("Get a tally of contributors' commits") var rootCommand = new RootCommand("Get a tally of contributors' commits")
{ {
outputOption, outputOption,
branchOption, branchOption,
tagOption,
}; };
rootCommand.SetHandler((outputOptionValue, branchOptionValue) => { rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue) => {
CommitDetail commits = new CommitDetail(); CommitDetail commits = new CommitDetail();
switch (outputOptionValue) switch (outputOptionValue)
@ -31,6 +38,10 @@ static class Program
StdOutDataService outDataService = new StdOutDataService(); StdOutDataService outDataService = new StdOutDataService();
DataAccess dataAccess = new DataAccess(outDataService); DataAccess dataAccess = new DataAccess(outDataService);
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) switch (branchOptionValue)
{ {
case null: case null:
@ -43,10 +54,19 @@ static class Program
break; break;
} }
break; break;
} else if (branchOptionValue == null && tagOptionValue != null) {
commits.GetCommitsByTag(tagOptionValue);
dataAccess.WriteData(commits.CommitDetails);
}
break;
case "xlsx": case "xlsx":
ExcelDataService excelDataService = new ExcelDataService(); ExcelDataService excelDataService = new ExcelDataService();
DataAccess dataAccessExcelCase = new DataAccess(excelDataService); DataAccess dataAccessExcelCase = new DataAccess(excelDataService);
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) switch (branchOptionValue)
{ {
case null: case null:
@ -59,10 +79,19 @@ static class Program
break; break;
} }
break; break;
} else if (branchOptionValue == null && tagOptionValue != null) {
commits.GetCommitsByTag(tagOptionValue);
dataAccessExcelCase.WriteData(commits.CommitDetails);
}
break;
case null: case null:
StdOutDataService stdOutDataService = new StdOutDataService(); StdOutDataService stdOutDataService = new StdOutDataService();
DataAccess dataAccessNullCase = new DataAccess(stdOutDataService); DataAccess dataAccessNullCase = new DataAccess(stdOutDataService);
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) switch (branchOptionValue)
{ {
case null: case null:
@ -75,13 +104,21 @@ static class Program
break; break;
} }
break; break;
} else if (branchOptionValue == null && tagOptionValue != null) {
commits.GetCommitsByTag(tagOptionValue);
dataAccessNullCase.WriteData(commits.CommitDetails);
} else {
commits.GetCurrentCommitsByName();
dataAccessNullCase.WriteData(commits.CommitDetails);
}
break;
default: default:
System.Console.WriteLine("This should not happen..."); System.Console.WriteLine("This should not happen...");
Environment.Exit(90); Environment.Exit(90);
break; break;
} }
}, },
outputOption, branchOption); outputOption, branchOption, tagOption);
rootCommand.Invoke(args); rootCommand.Invoke(args);
} }