From e92f9538980ea2779ba1571eb13e28640aceb15f Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Thu, 4 Aug 2022 15:55:42 -0400 Subject: [PATCH] added command line arguments --- Program.cs | 100 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 80 insertions(+), 20 deletions(-) diff --git a/Program.cs b/Program.cs index a07a0a2..d93bbc9 100644 --- a/Program.cs +++ b/Program.cs @@ -1,28 +1,88 @@ -using LibGit2Sharp; +using System.CommandLine; static class Program { internal static void Main(string[] args) { - try + var outputOption = new Option( + "--output", + "Specify the output given to the user" + ).FromAmong("stdout", "xlsx"); + outputOption.AddAlias("-o"); + + var branchOption = new Option( + "--branch", + "Specify the branch to filter by" + ); + branchOption.AddAlias("-b"); + + var rootCommand = new RootCommand("Get a tally of contributors' commits") { - CommitDetail commits = new CommitDetail(); - commits.GetAllCommitsByName(); - // SortedList results = commits.OrderCommitsByCount(); - //StdOutDataService outDataService = new StdOutDataService(); - ExcelDataService excelDataService = new ExcelDataService(); - //DataAccess dataAccess = new DataAccess(outDataService); - DataAccess dataAccess = new DataAccess(excelDataService); - dataAccess.WriteData(commits.CommitDetails); - } - catch (System.IO.DirectoryNotFoundException e) - { - Console.WriteLine($"Are you in a git repository? {e}"); - Environment.Exit(1); - } - catch (System.Exception e) - { - Console.WriteLine(e); - } + outputOption, + branchOption, + }; + + rootCommand.SetHandler((outputOptionValue, branchOptionValue) => { + CommitDetail commits = new CommitDetail(); + + switch (outputOptionValue) + { + case "stdout": + 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; + } + 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; + } + 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; + } + break; + default: + System.Console.WriteLine("This should not happen..."); + Environment.Exit(90); + break; + } + }, + outputOption, branchOption); + + rootCommand.Invoke(args); } }