Merge pull request 'Directory option' (#4) from dirOption into master
Reviewed-on: wymiller/DrillSergeant#4
This commit is contained in:
		@@ -5,6 +5,10 @@ public class CommitDetail
 | 
				
			|||||||
    private List<string>? _authors;
 | 
					    private List<string>? _authors;
 | 
				
			||||||
    private SortedList<string, int>? _commitDetails;
 | 
					    private SortedList<string, int>? _commitDetails;
 | 
				
			||||||
    private string _currentBranch;
 | 
					    private string _currentBranch;
 | 
				
			||||||
 | 
					    private string? _outputOption;
 | 
				
			||||||
 | 
					    private string? _branchOption;
 | 
				
			||||||
 | 
					    private string? _tagOption;
 | 
				
			||||||
 | 
					    private string? _selectedDir;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public List<string>? Authors
 | 
					    public List<string>? Authors
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -24,16 +28,28 @@ public class CommitDetail
 | 
				
			|||||||
        set { _currentBranch = value; }
 | 
					        set { _currentBranch = value; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public CommitDetail()
 | 
					    public string? SelectedDir
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        get { return _selectedDir; }
 | 
				
			||||||
 | 
					        set { _selectedDir = value; }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public CommitDetail(string? dir)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        _selectedDir = !String.IsNullOrEmpty(dir) ? dir : Directory.GetCurrentDirectory();
 | 
				
			||||||
        _authors = new List<string>();
 | 
					        _authors = new List<string>();
 | 
				
			||||||
        _commitDetails = new SortedList<string, int>();
 | 
					        _commitDetails = new SortedList<string, int>();
 | 
				
			||||||
        _currentBranch = GetCurrentBranch();
 | 
					        _currentBranch = GetCurrentBranch();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // unused, might be used later for a refactor
 | 
				
			||||||
 | 
					        _outputOption = null;
 | 
				
			||||||
 | 
					        _branchOption = null;
 | 
				
			||||||
 | 
					        _tagOption = null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void GetCurrentCommitsByName()
 | 
					    public void GetCurrentCommitsByName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        using (var repo = new Repository(Directory.GetCurrentDirectory()))
 | 
					        using (var repo = new Repository(_selectedDir))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            foreach (var c in repo.Commits)
 | 
					            foreach (var c in repo.Commits)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@@ -53,7 +69,7 @@ public class CommitDetail
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public void GetCurrentCommitsByEmail()
 | 
					    public void GetCurrentCommitsByEmail()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        using (var repo = new Repository(Directory.GetCurrentDirectory()))
 | 
					        using (var repo = new Repository(_selectedDir))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            foreach (var c in repo.Commits)
 | 
					            foreach (var c in repo.Commits)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@@ -73,7 +89,7 @@ public class CommitDetail
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public int GetCommitTotal()
 | 
					    public int GetCommitTotal()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        using (var repo = new Repository(Directory.GetCurrentDirectory()))
 | 
					        using (var repo = new Repository(_selectedDir))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            return repo.Commits.Count();
 | 
					            return repo.Commits.Count();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -81,7 +97,7 @@ public class CommitDetail
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public string GetCurrentBranch()
 | 
					    public string GetCurrentBranch()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        using (var repo = new Repository(Directory.GetCurrentDirectory()))
 | 
					        using (var repo = new Repository(_selectedDir))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            return repo.Head.Reference.TargetIdentifier;
 | 
					            return repo.Head.Reference.TargetIdentifier;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -89,7 +105,7 @@ public class CommitDetail
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public void GetCommitsByBranch(string branchName)
 | 
					    public void GetCommitsByBranch(string branchName)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        using (var repo = new Repository(Directory.GetCurrentDirectory()))
 | 
					        using (var repo = new Repository(_selectedDir))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var branchResult = repo.Branches[branchName];
 | 
					            var branchResult = repo.Branches[branchName];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -126,7 +142,7 @@ public class CommitDetail
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public void GetCommitsByTag(string tagName)
 | 
					    public void GetCommitsByTag(string tagName)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        using (var repo = new Repository(Directory.GetCurrentDirectory()))
 | 
					        using (var repo = new Repository(_selectedDir))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,7 @@
 | 
				
			|||||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
					    <ImplicitUsings>enable</ImplicitUsings>
 | 
				
			||||||
    <Nullable>enable</Nullable>
 | 
					    <Nullable>enable</Nullable>
 | 
				
			||||||
    <AssemblyName>drillsergeant</AssemblyName>
 | 
					    <AssemblyName>drillsergeant</AssemblyName>
 | 
				
			||||||
    <Version>1.1.0</Version>
 | 
					    <Version>1.2.0</Version>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										54
									
								
								Program.cs
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								Program.cs
									
									
									
									
									
								
							@@ -22,15 +22,23 @@ static class Program
 | 
				
			|||||||
                );
 | 
					                );
 | 
				
			||||||
        tagOption.AddAlias("-t");
 | 
					        tagOption.AddAlias("-t");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var dirOption = new Option<string>(
 | 
				
			||||||
 | 
					                "--file",
 | 
				
			||||||
 | 
					                "Specify a git directory"
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					        dirOption.AddAlias("-f");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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,
 | 
					            tagOption,
 | 
				
			||||||
 | 
					            dirOption,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue) => {
 | 
					        rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue, dirOptionValue) =>
 | 
				
			||||||
                    CommitDetail commits = new CommitDetail();
 | 
					        {
 | 
				
			||||||
 | 
					            CommitDetail commits = new CommitDetail(dirOptionValue);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            switch (outputOptionValue)
 | 
					            switch (outputOptionValue)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@@ -38,10 +46,13 @@ 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) {
 | 
					                    if (branchOptionValue != null && tagOptionValue != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        Console.WriteLine("Please specify either a branch or a tag");
 | 
					                        Console.WriteLine("Please specify either a branch or a tag");
 | 
				
			||||||
                        Environment.Exit(2);
 | 
					                        Environment.Exit(2);
 | 
				
			||||||
                            } else if (branchOptionValue != null && tagOptionValue == null) {
 | 
					                    }
 | 
				
			||||||
 | 
					                    else if (branchOptionValue != null && tagOptionValue == null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        switch (branchOptionValue)
 | 
					                        switch (branchOptionValue)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            case null:
 | 
					                            case null:
 | 
				
			||||||
@@ -53,8 +64,9 @@ static class Program
 | 
				
			|||||||
                                dataAccess.WriteData(commits.CommitDetails);
 | 
					                                dataAccess.WriteData(commits.CommitDetails);
 | 
				
			||||||
                                break;
 | 
					                                break;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                                break;
 | 
					                    }
 | 
				
			||||||
                            } else if (branchOptionValue == null && tagOptionValue != null) {
 | 
					                    else if (branchOptionValue == null && tagOptionValue != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        commits.GetCommitsByTag(tagOptionValue);
 | 
					                        commits.GetCommitsByTag(tagOptionValue);
 | 
				
			||||||
                        dataAccess.WriteData(commits.CommitDetails);
 | 
					                        dataAccess.WriteData(commits.CommitDetails);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@@ -63,10 +75,13 @@ static class Program
 | 
				
			|||||||
                    ExcelDataService excelDataService = new ExcelDataService();
 | 
					                    ExcelDataService excelDataService = new ExcelDataService();
 | 
				
			||||||
                    DataAccess dataAccessExcelCase = new DataAccess(excelDataService);
 | 
					                    DataAccess dataAccessExcelCase = new DataAccess(excelDataService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            if (branchOptionValue != null && tagOptionValue != null) {
 | 
					                    if (branchOptionValue != null && tagOptionValue != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        Console.WriteLine("Please specify either a branch or a tag.");
 | 
					                        Console.WriteLine("Please specify either a branch or a tag.");
 | 
				
			||||||
                        Environment.Exit(2);
 | 
					                        Environment.Exit(2);
 | 
				
			||||||
                            } else if (branchOptionValue != null && tagOptionValue == null) {
 | 
					                    }
 | 
				
			||||||
 | 
					                    else if (branchOptionValue != null && tagOptionValue == null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        switch (branchOptionValue)
 | 
					                        switch (branchOptionValue)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            case null:
 | 
					                            case null:
 | 
				
			||||||
@@ -78,8 +93,9 @@ static class Program
 | 
				
			|||||||
                                dataAccessExcelCase.WriteData(commits.CommitDetails);
 | 
					                                dataAccessExcelCase.WriteData(commits.CommitDetails);
 | 
				
			||||||
                                break;
 | 
					                                break;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                                break;
 | 
					                    }
 | 
				
			||||||
                            } else if (branchOptionValue == null && tagOptionValue != null) {
 | 
					                    else if (branchOptionValue == null && tagOptionValue != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        commits.GetCommitsByTag(tagOptionValue);
 | 
					                        commits.GetCommitsByTag(tagOptionValue);
 | 
				
			||||||
                        dataAccessExcelCase.WriteData(commits.CommitDetails);
 | 
					                        dataAccessExcelCase.WriteData(commits.CommitDetails);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@@ -104,10 +120,13 @@ static class Program
 | 
				
			|||||||
                    StdOutDataService stdOutDataService = new StdOutDataService();
 | 
					                    StdOutDataService stdOutDataService = new StdOutDataService();
 | 
				
			||||||
                    DataAccess dataAccessNullCase = new DataAccess(stdOutDataService);
 | 
					                    DataAccess dataAccessNullCase = new DataAccess(stdOutDataService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            if (branchOptionValue != null && tagOptionValue != null) {
 | 
					                    if (branchOptionValue != null && tagOptionValue != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        Console.WriteLine("Please specify either a branch or a tag.");
 | 
					                        Console.WriteLine("Please specify either a branch or a tag.");
 | 
				
			||||||
                        Environment.Exit(2);
 | 
					                        Environment.Exit(2);
 | 
				
			||||||
                            } else if (branchOptionValue != null && tagOptionValue == null) {
 | 
					                    }
 | 
				
			||||||
 | 
					                    else if (branchOptionValue != null && tagOptionValue == null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        switch (branchOptionValue)
 | 
					                        switch (branchOptionValue)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            case null:
 | 
					                            case null:
 | 
				
			||||||
@@ -119,11 +138,14 @@ static class Program
 | 
				
			|||||||
                                dataAccessNullCase.WriteData(commits.CommitDetails);
 | 
					                                dataAccessNullCase.WriteData(commits.CommitDetails);
 | 
				
			||||||
                                break;
 | 
					                                break;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                                break;
 | 
					                    }
 | 
				
			||||||
                            } else if (branchOptionValue == null && tagOptionValue != null) {
 | 
					                    else if (branchOptionValue == null && tagOptionValue != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        commits.GetCommitsByTag(tagOptionValue);
 | 
					                        commits.GetCommitsByTag(tagOptionValue);
 | 
				
			||||||
                        dataAccessNullCase.WriteData(commits.CommitDetails);
 | 
					                        dataAccessNullCase.WriteData(commits.CommitDetails);
 | 
				
			||||||
                            } else {
 | 
					                    }
 | 
				
			||||||
 | 
					                    else
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        commits.GetCurrentCommitsByName();
 | 
					                        commits.GetCurrentCommitsByName();
 | 
				
			||||||
                        dataAccessNullCase.WriteData(commits.CommitDetails);
 | 
					                        dataAccessNullCase.WriteData(commits.CommitDetails);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@@ -134,7 +156,7 @@ static class Program
 | 
				
			|||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
                outputOption, branchOption, tagOption);
 | 
					                outputOption, branchOption, tagOption, dirOption);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        rootCommand.Invoke(args);
 | 
					        rootCommand.Invoke(args);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user