added command line arguments
This commit is contained in:
		
							
								
								
									
										88
									
								
								Program.cs
									
									
									
									
									
								
							
							
						
						
									
										88
									
								
								Program.cs
									
									
									
									
									
								
							@@ -1,28 +1,88 @@
 | 
				
			|||||||
using LibGit2Sharp;
 | 
					using System.CommandLine;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static class Program
 | 
					static class Program
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    internal static void Main(string[] args)
 | 
					    internal static void Main(string[] args)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        try 
 | 
					        var outputOption = new Option<string>(
 | 
				
			||||||
 | 
					                "--output",
 | 
				
			||||||
 | 
					                "Specify the output given to the user"
 | 
				
			||||||
 | 
					                ).FromAmong("stdout", "xlsx");
 | 
				
			||||||
 | 
					        outputOption.AddAlias("-o");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var branchOption = new Option<string>(
 | 
				
			||||||
 | 
					                "--branch",
 | 
				
			||||||
 | 
					                "Specify the branch to filter by"
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					        branchOption.AddAlias("-b");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var rootCommand = new RootCommand("Get a tally of contributors' commits")
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            outputOption,
 | 
				
			||||||
 | 
					            branchOption,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        rootCommand.SetHandler((outputOptionValue, branchOptionValue) => {
 | 
				
			||||||
                    CommitDetail commits = new CommitDetail();
 | 
					                    CommitDetail commits = new CommitDetail();
 | 
				
			||||||
            commits.GetAllCommitsByName();
 | 
					                    
 | 
				
			||||||
            // SortedList<string, int> results = commits.OrderCommitsByCount();
 | 
					                    switch (outputOptionValue) 
 | 
				
			||||||
            //StdOutDataService outDataService = new StdOutDataService();
 | 
					                    {
 | 
				
			||||||
            ExcelDataService excelDataService = new ExcelDataService();
 | 
					                        case "stdout":
 | 
				
			||||||
            //DataAccess dataAccess = new DataAccess(outDataService);
 | 
					                            StdOutDataService outDataService = new StdOutDataService();
 | 
				
			||||||
            DataAccess dataAccess = new DataAccess(excelDataService);
 | 
					                            DataAccess dataAccess = new DataAccess(outDataService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            switch (branchOptionValue) 
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                case null:
 | 
				
			||||||
 | 
					                                    commits.GetCurrentCommitsByName();
 | 
				
			||||||
                                    dataAccess.WriteData(commits.CommitDetails);
 | 
					                                    dataAccess.WriteData(commits.CommitDetails);
 | 
				
			||||||
 | 
					                                    break;
 | 
				
			||||||
 | 
					                                default:
 | 
				
			||||||
 | 
					                                    commits.GetCommitsByBranch(branchOptionValue);
 | 
				
			||||||
 | 
					                                    dataAccess.WriteData(commits.CommitDetails);
 | 
				
			||||||
 | 
					                                    break;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
        catch (System.IO.DirectoryNotFoundException e)
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case "xlsx":
 | 
				
			||||||
 | 
					                            ExcelDataService excelDataService = new ExcelDataService();
 | 
				
			||||||
 | 
					                            DataAccess dataAccessExcelCase = new DataAccess(excelDataService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            switch (branchOptionValue)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
            Console.WriteLine($"Are you in a git repository? {e}");
 | 
					                                case null:
 | 
				
			||||||
            Environment.Exit(1);
 | 
					                                    commits.GetCurrentCommitsByName();
 | 
				
			||||||
 | 
					                                    dataAccessExcelCase.WriteData(commits.CommitDetails);
 | 
				
			||||||
 | 
					                                    break;
 | 
				
			||||||
 | 
					                                default:
 | 
				
			||||||
 | 
					                                    commits.GetCommitsByBranch(branchOptionValue);
 | 
				
			||||||
 | 
					                                    dataAccessExcelCase.WriteData(commits.CommitDetails);
 | 
				
			||||||
 | 
					                                    break;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
        catch (System.Exception e)
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case null:
 | 
				
			||||||
 | 
					                            StdOutDataService stdOutDataService = new StdOutDataService();
 | 
				
			||||||
 | 
					                            DataAccess dataAccessNullCase = new DataAccess(stdOutDataService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            switch (branchOptionValue)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
            Console.WriteLine(e);
 | 
					                                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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user