2022-08-04 14:55:42 -05:00
|
|
|
|
using System.CommandLine;
|
2022-07-29 17:18:24 -05:00
|
|
|
|
|
2022-07-29 18:51:22 -05:00
|
|
|
|
static class Program
|
2022-07-29 17:18:24 -05:00
|
|
|
|
{
|
|
|
|
|
internal static void Main(string[] args)
|
|
|
|
|
{
|
2022-08-04 14:55:42 -05:00
|
|
|
|
var outputOption = new Option<string>(
|
|
|
|
|
"--output",
|
|
|
|
|
"Specify the output given to the user"
|
2022-08-23 10:30:01 -05:00
|
|
|
|
).FromAmong("stdout", "xlsx", "pdf");
|
2022-08-04 14:55:42 -05:00
|
|
|
|
outputOption.AddAlias("-o");
|
|
|
|
|
|
|
|
|
|
var branchOption = new Option<string>(
|
|
|
|
|
"--branch",
|
|
|
|
|
"Specify the branch to filter by"
|
|
|
|
|
);
|
|
|
|
|
branchOption.AddAlias("-b");
|
|
|
|
|
|
2022-08-23 17:57:18 -05:00
|
|
|
|
var tagOption = new Option<string>(
|
|
|
|
|
"--tag",
|
|
|
|
|
"Specify the tag to filter by"
|
|
|
|
|
);
|
|
|
|
|
tagOption.AddAlias("-t");
|
|
|
|
|
|
2022-08-04 14:55:42 -05:00
|
|
|
|
var rootCommand = new RootCommand("Get a tally of contributors' commits")
|
2022-07-29 17:18:24 -05:00
|
|
|
|
{
|
2022-08-04 14:55:42 -05:00
|
|
|
|
outputOption,
|
|
|
|
|
branchOption,
|
2022-08-23 17:57:18 -05:00
|
|
|
|
tagOption,
|
2022-08-04 14:55:42 -05:00
|
|
|
|
};
|
|
|
|
|
|
2022-08-23 17:57:18 -05:00
|
|
|
|
rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue) => {
|
2022-08-04 14:55:42 -05:00
|
|
|
|
CommitDetail commits = new CommitDetail();
|
|
|
|
|
|
|
|
|
|
switch (outputOptionValue)
|
|
|
|
|
{
|
|
|
|
|
case "stdout":
|
|
|
|
|
StdOutDataService outDataService = new StdOutDataService();
|
|
|
|
|
DataAccess dataAccess = new DataAccess(outDataService);
|
|
|
|
|
|
2022-08-23 17:57:18 -05:00
|
|
|
|
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);
|
2022-08-04 14:55:42 -05:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "xlsx":
|
|
|
|
|
ExcelDataService excelDataService = new ExcelDataService();
|
|
|
|
|
DataAccess dataAccessExcelCase = new DataAccess(excelDataService);
|
|
|
|
|
|
2022-08-23 17:57:18 -05:00
|
|
|
|
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);
|
2022-08-04 14:55:42 -05:00
|
|
|
|
}
|
|
|
|
|
break;
|
2022-08-23 10:30:01 -05:00
|
|
|
|
case "pdf":
|
|
|
|
|
PdfDataService pdfDataService = new PdfDataService();
|
|
|
|
|
DataAccess dataAccessPdfCase = new DataAccess(pdfDataService);
|
|
|
|
|
|
|
|
|
|
switch (branchOptionValue)
|
|
|
|
|
{
|
|
|
|
|
case null:
|
|
|
|
|
commits.GetCurrentCommitsByName();
|
|
|
|
|
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
commits.GetCommitsByBranch(branchOptionValue);
|
|
|
|
|
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2022-08-04 14:55:42 -05:00
|
|
|
|
case null:
|
|
|
|
|
StdOutDataService stdOutDataService = new StdOutDataService();
|
|
|
|
|
DataAccess dataAccessNullCase = new DataAccess(stdOutDataService);
|
|
|
|
|
|
2022-08-23 17:57:18 -05:00
|
|
|
|
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);
|
2022-08-04 14:55:42 -05:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
System.Console.WriteLine("This should not happen...");
|
|
|
|
|
Environment.Exit(90);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-08-23 17:57:18 -05:00
|
|
|
|
outputOption, branchOption, tagOption);
|
2022-08-04 14:55:42 -05:00
|
|
|
|
|
|
|
|
|
rootCommand.Invoke(args);
|
2022-07-29 17:18:24 -05:00
|
|
|
|
}
|
|
|
|
|
}
|