Skip to content

Commit

Permalink
Creating a cli-tool
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterjanDeClippel committed Jan 12, 2025
1 parent 81815b3 commit 2e4a3bc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Verz/MintPlayer.Verz/MintPlayer.Verz.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.0.3</Version>
Expand All @@ -15,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions Verz/MintPlayer.Verz/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// dotnet tool install --global MintPlayer.Verz

using System.CommandLine;
using System.Reflection;

namespace MintPlayer.Verz;

Expand All @@ -16,10 +17,50 @@ static async Task<int> Main(string[] args)
rootCommand.AddOption(fileOption);
rootCommand.SetHandler(file => ReadFile(file!), fileOption);

var packagesCommand = new Command("packages", "Manage globally installed nuget packages");
rootCommand.AddCommand(packagesCommand);

var listPackagesCommand = new Command("list", "Lists all globally installed nuget packages");
packagesCommand.AddCommand(listPackagesCommand);
listPackagesCommand.SetHandler(async () =>
{


var globalPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");
var modules = Directory.GetDirectories(globalPath);
var moduleAssemblies = await Task.WhenAll(modules.Select(m => AnalyzeModule(m)));
var validModules = moduleAssemblies.Where(asm => asm is not null && asm.IsFullyTrusted).ToList();
});

var statusCode = await rootCommand.InvokeAsync(args);
return statusCode;
}

private static async Task<Assembly?> AnalyzeModule(string modulePath)
{
await Task.CompletedTask;

var firstVersion = Directory.EnumerateDirectories(modulePath).FirstOrDefault();
if (firstVersion == null) return null;

var libFolder = Path.Combine(firstVersion, "lib");
if (!Directory.Exists(libFolder)) return null;

var moduleName = Path.GetFileName(modulePath);
var entryPoint = Directory.EnumerateFiles(libFolder, $"{moduleName}.dll", SearchOption.AllDirectories).LastOrDefault();
if (entryPoint == null) return null;

try
{
var asm = Assembly.LoadFrom(entryPoint);
return asm;
}
catch (Exception)
{
return null;
}
}

static async Task ReadFile(FileInfo file)
{
var lines = await File.ReadAllLinesAsync(file.FullName);
Expand Down
2 changes: 1 addition & 1 deletion Verz/MintPlayer.Verz/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"MintPlayer.Verz": {
"commandName": "Project",
"commandLineArgs": "--file \"C:\\Repos\\debug.log\""
"commandLineArgs": "packages list"
}
}
}
18 changes: 18 additions & 0 deletions Verz/MintPlayer.Verz/VerzConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace MintPlayer.Verz
{
public class VerzConfig
{
public VerzFeed[] Feeds { get; set; } = [];
public VerzSdk[] Sdks { get; set; } = [];
}

public class VerzFeed
{
public string? Url { get; set; }
}

public class VerzSdk
{

}
}

0 comments on commit 2e4a3bc

Please sign in to comment.