diff --git a/src/ModuleCore/Git/GitManager.cs b/src/ModuleCore/Git/GitManager.cs index 702d0e1..fe1f69e 100644 --- a/src/ModuleCore/Git/GitManager.cs +++ b/src/ModuleCore/Git/GitManager.cs @@ -52,30 +52,4 @@ public class GitManager throw new Exception($"Git repo already registered with the name {registrationName}"); } - - public List ListRepos() - { - return _registrations.Select(x => new GitReg() { Name = x.Value.Name, Location = x.Value.Location }).ToList(); - } - - public string GetRepo(string? registeredName) - { - if (string.IsNullOrEmpty(registeredName)) - { - throw new Exception("Name cannot be null"); - } - - if (_registrations.TryGetValue(registeredName, out var registration)) - { - return registration.Location; - } - - throw new Exception($"No git repo has been registered with the name {registeredName}"); - } -} - -public class GitReg -{ - public required string Name { get; set; } - public required string Location { get; set; } } \ No newline at end of file diff --git a/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs b/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs deleted file mode 100644 index 1859375..0000000 --- a/src/PowershellModule/Git/Commands/GetGitRepoCommand.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Management.Automation; -using ModuleCore.Git; - -namespace PowershellModule.Git.Commands; - -[Cmdlet(VerbsCommon.Get, GitCommands.GitRepoNoun)] -public class ListGitRepoCommand : PSCmdlet -{ - protected override void BeginProcessing() - { - var repos = GitManager.Instance.ListRepos(); - - WriteObject(repos); - - base.BeginProcessing(); - } -} \ No newline at end of file diff --git a/src/PowershellModule/Git/Commands/GitCommands.cs b/src/PowershellModule/Git/Commands/GitCommands.cs deleted file mode 100644 index 2d5c888..0000000 --- a/src/PowershellModule/Git/Commands/GitCommands.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace PowershellModule.Git.Commands; - -public class GitCommands -{ - public const string GitRepoNoun = "GitRepo"; -} \ No newline at end of file diff --git a/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs b/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs index 5aabd59..ba56252 100644 --- a/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs +++ b/src/PowershellModule/Git/Commands/NewGitRepoCommand.cs @@ -6,9 +6,11 @@ using ModuleCore.Git; namespace PowershellModule.Git.Commands; -[Cmdlet(VerbsCommon.New, GitCommands.GitRepoNoun)] +[Cmdlet(VerbsCommon.New, Noun)] public sealed class NewGitRepoCommand : PSCmdlet { + private const string Noun = "GitRepo"; + [Parameter( Position = 0, ValueFromPipeline = true, diff --git a/src/PowershellModule/Git/Commands/SetGitRepoCommand.cs b/src/PowershellModule/Git/Commands/SetGitRepoCommand.cs index 69c4a34..4ccb140 100644 --- a/src/PowershellModule/Git/Commands/SetGitRepoCommand.cs +++ b/src/PowershellModule/Git/Commands/SetGitRepoCommand.cs @@ -4,10 +4,11 @@ using ModuleCore.Git; namespace PowershellModule.Git.Commands; -// TODO: decide if I want to use this verb instead of show. Currently this implementation is under Show-GitRepo -[Cmdlet(VerbsCommon.Set, GitCommands.GitRepoNoun)] +[Cmdlet(VerbsCommon.Set, Noun)] public class SetGitRepoCommand : PSCmdlet { + private const string Noun = "GitRepo"; + public SetGitRepoCommand() { Console.WriteLine($"{nameof(NewGitRepoCommand)} init"); diff --git a/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs b/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs deleted file mode 100644 index 3394ef3..0000000 --- a/src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Management.Automation; -using ModuleCore.Git; - -namespace PowershellModule.Git.Commands; - -[Cmdlet(VerbsCommon.Show, GitCommands.GitRepoNoun)] -public class ShowGitRepoCommand : PSCmdlet -{ - [Parameter( - Position = 0, - ValueFromPipeline = true, - Mandatory = true, - HelpMessage = "Reference name for the repo")] - public string? Name { get; set; } - - [Parameter( - Mandatory = false, - HelpMessage = "Changes directory directly instead of using Set-Location")] - [Alias("NoSetLocation")] - public SwitchParameter NoStack { get; set; } - - protected override void BeginProcessing() - { - var location = GitManager.Instance.GetRepo(Name); - - // By default instead of doing the same as cd, we instead do pushd so a user can popd straight back to where - // they came from. - // TODO: incorporate this into the custom prompt when I develop that - if (!NoStack) - { - // Push the current location to the stack - // TODO: support named stacks. PowerShell *-Location commands support named stacks, but I don't personally - // use them myself so I haven't implemented them initially. I would like to in the future though, but right - // now it's low value to me. - // https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-location?view=powershell-7.6#example-4-set-the-current-location-to-a-named-stack - SessionState.Path.PushCurrentLocation(null); - } - - SessionState.Path.SetLocation(location); - base.BeginProcessing(); - } -} \ No newline at end of file