feat(git-provider): Initial Show-GitRepo implementation
This commit is contained in:
parent
af5c9e43b6
commit
740d35d3e7
2 changed files with 60 additions and 0 deletions
|
|
@ -57,6 +57,21 @@ public class GitManager
|
||||||
{
|
{
|
||||||
return _registrations.Select(x => new GitReg() { Name = x.Value.Name, Location = x.Value.Location }).ToList();
|
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 class GitReg
|
||||||
|
|
|
||||||
45
src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs
Normal file
45
src/PowershellModule/Git/Commands/ShowGitRepoCommand.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
using System;
|
||||||
|
using System.Management.Automation;
|
||||||
|
using ModuleCore.Git;
|
||||||
|
|
||||||
|
namespace PowershellModule.Git.Commands;
|
||||||
|
|
||||||
|
[Cmdlet(VerbsCommon.Show, Noun)]
|
||||||
|
public class ShowGitRepoCommand : PSCmdlet
|
||||||
|
{
|
||||||
|
private const string Noun = "GitRepo";
|
||||||
|
|
||||||
|
[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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue