86 lines
No EOL
2.8 KiB
C#
86 lines
No EOL
2.8 KiB
C#
using System;
|
|
using System.Management.Automation;
|
|
using System.Management.Automation.Provider;
|
|
|
|
namespace PowershellModule.Git;
|
|
|
|
// https://learn.microsoft.com/en-us/powershell/scripting/developer/provider/accessdbprovidersample02?view=powershell-7.6
|
|
[CmdletProvider(Name, ProviderCapabilities.None)]
|
|
public class GitProvider : NavigationCmdletProvider
|
|
{
|
|
public const string Name = "GitRepo";
|
|
|
|
public GitProvider()
|
|
{
|
|
}
|
|
|
|
protected override PSDriveInfo NewDrive(PSDriveInfo drive)
|
|
{
|
|
// This is a bit of a hack to ensure that no drive is registered with a root location.
|
|
// It seems to be how PSDrives are registered for Alias providers, and we technically don't have any concept
|
|
// of a normal file system
|
|
if (drive.Root != string.Empty)
|
|
{
|
|
throw new Exception("Drive root must be an empty string");
|
|
}
|
|
|
|
return base.NewDrive(drive);
|
|
}
|
|
|
|
protected override void NewItem(string path, string itemTypeName, object newItemValue)
|
|
{
|
|
//base.NewItem(path, itemTypeName, newItemValue);
|
|
}
|
|
|
|
protected override PSDriveInfo RemoveDrive(PSDriveInfo drive)
|
|
{
|
|
return base.RemoveDrive(drive);
|
|
}
|
|
|
|
protected override void GetChildNames(string path, ReturnContainers returnContainers)
|
|
{
|
|
// TODO: get all configured repos based on a path from the underlying GitPsDriveInfo then
|
|
// output their repository names
|
|
}
|
|
|
|
protected override void GetChildItems(string path, bool recurse)
|
|
{
|
|
// TODO: get all configured repos based on a path from the underlying GitPsDriveInfo then
|
|
// output their repository locations and any other meta data I store
|
|
}
|
|
|
|
// I think this is needed to be able to cd into it
|
|
protected override bool IsItemContainer(string path)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// I think this is needed to be able to cd into it
|
|
protected override bool ItemExists(string path)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected override string MakePath(string parent, string child)
|
|
{
|
|
// Test to see what happens if set the location if the path matches a pretend repo registered with the name test
|
|
// The result of the test is that yes, this does work, but there's also a shit load of calls to this method as
|
|
// it traverses the entire directory path.
|
|
// This seems to just be internal powershell behaviour so as long as this is quick the first time, everything
|
|
// afterwards just always happens. But probably happens more seeing as I'm changing the location of the path
|
|
// in this current SessionState and probably doesn't happen if this were a normal path traversal
|
|
// where I don't set the location.
|
|
if (child == "test")
|
|
{
|
|
SessionState.Path.SetLocation("F:/Repos/PowershellModule/src/PowershellModule/Git");
|
|
return "F:/Repos/PowershellModule/src/PowershellModule/Git";
|
|
}
|
|
|
|
return base.MakePath(parent, child);
|
|
}
|
|
|
|
protected override bool IsValidPath(string path)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
} |