Set up options and arguments for install command.
This commit is contained in:
parent
cc715abcd6
commit
8a5ca53519
26
.vscode/launch.json
vendored
Normal file
26
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/MCCFMD/bin/Debug/net6.0/MCCFMD.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/MCCFMD",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
}
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"MCCFMD"
|
||||
]
|
||||
}
|
41
.vscode/tasks.json
vendored
Normal file
41
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/MCCFMD/MCCFMD.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/MCCFMD/MCCFMD.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"--project",
|
||||
"${workspaceFolder}/MCCFMD/MCCFMD.csproj"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
55
MCCFMD/Commands/Install.cs
Normal file
55
MCCFMD/Commands/Install.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.CommandLine;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MCCFMD.Commands
|
||||
{
|
||||
public class Install : Command
|
||||
{
|
||||
const string NAME = "install";
|
||||
const string DESC = "Install the profile described by the manifest.";
|
||||
public Install(DirectoryInfo workspaceDir) : base(NAME, DESC)
|
||||
{
|
||||
Argument<FileInfo> profileFile = new Argument<FileInfo>("profile", "The .zip file describing the profile to install.");
|
||||
Add(profileFile);
|
||||
|
||||
Option<DirectoryInfo?> destination = new Option<DirectoryInfo?>("--destination", "Where to install the profile.");
|
||||
destination.AddAlias("-d");
|
||||
Add(destination);
|
||||
|
||||
Option<bool> server = new Option<bool>("--server", "Install server files.");
|
||||
server.AddAlias("-s");
|
||||
Add(server);
|
||||
|
||||
Option<DirectoryInfo?> client = new Option<DirectoryInfo?>("--client", "Install files in local client.");
|
||||
client.AddAlias("-c");
|
||||
Add(client);
|
||||
|
||||
Option<FileInfo?> fileExclude = new Option<FileInfo?>("--exclude-file", "Excludes files with IDs listed in a given file.");
|
||||
fileExclude.AddAlias("-E");
|
||||
Add(fileExclude);
|
||||
|
||||
Option<FileInfo?> fileInclude = new Option<FileInfo?>("--include-file", "Includes files with IDs listed in a given file.");
|
||||
fileInclude.AddAlias("-I");
|
||||
Add(fileInclude);
|
||||
|
||||
Option<IEnumerable<FileInfo>> excludeIds = new Option<IEnumerable<FileInfo>>
|
||||
("--exclude-id", "Excludes the files with the given IDs.");
|
||||
excludeIds.AllowMultipleArgumentsPerToken = true;
|
||||
excludeIds.AddAlias("-e");
|
||||
Add(excludeIds);
|
||||
|
||||
Option<IEnumerable<FileInfo>> includeIds = new Option<IEnumerable<FileInfo>>("--include-id", "Include the files with the given IDs");
|
||||
includeIds.AllowMultipleArgumentsPerToken = true;
|
||||
includeIds.AddAlias("-i");
|
||||
Add(includeIds);
|
||||
|
||||
this.SetHandler(async (FileInfo profileFile, DirectoryInfo? dest, bool server, bool client, FileInfo? fileExclude, FileInfo? fileInclude, IEnumerable<FileInfo> excludeIds, IEnumerable<FileInfo> includeIds) =>
|
||||
{
|
||||
|
||||
}, profileFile, destination, client, fileExclude, fileInclude, excludeIds, includeIds);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,8 +3,12 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<ImplicitUsings>false</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,2 +1,21 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.CommandLine;
|
||||
using System.Threading.Tasks;
|
||||
using MCCFMD.Commands;
|
||||
|
||||
namespace MCCFMD
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
// See: https://docs.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates
|
||||
static async Task<int> Main(string[] args)
|
||||
{
|
||||
DirectoryInfo workspace = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
|
||||
Directory.CreateDirectory(workspace.FullName);
|
||||
RootCommand rootCmd = new RootCommand("CLI utility for creating, editing, and installing Curseforge profiles.");
|
||||
rootCmd.Add(new Install(workspace));
|
||||
return await rootCmd.InvokeAsync(args);
|
||||
}
|
||||
}
|
||||
}
|
77
MCCFMD/Serialization/ManifestConverter.cs
Normal file
77
MCCFMD/Serialization/ManifestConverter.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using MCCFMD.Serialization.Modpack;
|
||||
|
||||
namespace MCCFMD.Serialization
|
||||
{
|
||||
public class ManifestConverter : JsonConverter<Manifest>
|
||||
{
|
||||
PropertyInfo[] manifestProperties;
|
||||
Type manifestType;
|
||||
|
||||
public ManifestConverter()
|
||||
{
|
||||
manifestType = typeof(Manifest);
|
||||
manifestProperties = manifestType.GetProperties();
|
||||
}
|
||||
public override Manifest Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
string[] propertyNames = new string[manifestProperties.Length];
|
||||
for (int i = 0; i < propertyNames.Length; i++) propertyNames[i] = manifestProperties[i].Name;
|
||||
Manifest result = new Manifest();
|
||||
HashSet<string> pendingProperties = new HashSet<string>(propertyNames);
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
if (pendingProperties.Count != 0)
|
||||
{
|
||||
throw new JsonException("Manifest is missing data. Will not proceed.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.PropertyName)
|
||||
{
|
||||
string propertyName = reader.GetString() ?? throw new JsonException();
|
||||
if (propertyNames.Contains(propertyName))
|
||||
{
|
||||
PropertyInfo property = manifestProperties[Array.IndexOf(propertyNames, propertyName)];
|
||||
pendingProperties.Remove(propertyName);
|
||||
property.SetValue(result, JsonSerializer.Deserialize(ref reader, property.PropertyType, options));
|
||||
}
|
||||
else if (Enum.GetNames(typeof(ManifestGames)).Contains(propertyName, StringComparer.CurrentCultureIgnoreCase))
|
||||
{
|
||||
Game game = JsonSerializer.Deserialize<Game>(ref reader);
|
||||
game.gameType = Enum.Parse<ManifestGames>(propertyName, true);
|
||||
result.game = game;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonException();
|
||||
}
|
||||
}
|
||||
throw new JsonException(); // Reached end of stream and did not find ending token.
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Manifest value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName(value.game.gameType.ToString().ToLower());
|
||||
JsonSerializer.Serialize(writer, value.game, typeof(Game), options);
|
||||
for (int i = 0; i < manifestProperties.Length; i++)
|
||||
{
|
||||
PropertyInfo property = manifestProperties[i];
|
||||
writer.WritePropertyName(property.Name);
|
||||
JsonSerializer.Serialize(writer, property.GetValue(value), property.PropertyType, options);
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
}
|
4
MCCFMD/Serialization/ManifestGames.cs
Normal file
4
MCCFMD/Serialization/ManifestGames.cs
Normal file
@ -0,0 +1,4 @@
|
||||
public enum ManifestGames
|
||||
{
|
||||
Minecraft
|
||||
}
|
9
MCCFMD/Serialization/Modpack/File.cs
Normal file
9
MCCFMD/Serialization/Modpack/File.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace MCCFMD.Serialization.Modpack
|
||||
{
|
||||
public struct File
|
||||
{
|
||||
public string ProjectId { get; set; }
|
||||
public string FileId { get; set; }
|
||||
public bool Required { get; set; }
|
||||
}
|
||||
}
|
12
MCCFMD/Serialization/Modpack/Game.cs
Normal file
12
MCCFMD/Serialization/Modpack/Game.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
namespace MCCFMD.Serialization.Modpack
|
||||
{
|
||||
public struct Game
|
||||
{
|
||||
[JsonIgnore]
|
||||
public ManifestGames gameType;
|
||||
public string Version { get; set; }
|
||||
public IList<ModLoader> ModLoaders { get; set; }
|
||||
}
|
||||
}
|
19
MCCFMD/Serialization/Modpack/Manifest.cs
Normal file
19
MCCFMD/Serialization/Modpack/Manifest.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MCCFMD.Serialization.Modpack
|
||||
{
|
||||
public struct Manifest
|
||||
{
|
||||
[JsonIgnore]
|
||||
public Game game;
|
||||
public string ManifestType { get; set; }
|
||||
public int ManifestVersion { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Version { get; set; }
|
||||
public string Author { get; set; }
|
||||
public IList<File> Files { get; set; }
|
||||
public string Overrides { get; set; }
|
||||
}
|
||||
}
|
8
MCCFMD/Serialization/Modpack/ModLoader.cs
Normal file
8
MCCFMD/Serialization/Modpack/ModLoader.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace MCCFMD.Serialization.Modpack
|
||||
{
|
||||
public struct ModLoader
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public bool Primary { get; set; }
|
||||
}
|
||||
}
|
7
MCCFMD/Serialization/ProfileReader.cs
Normal file
7
MCCFMD/Serialization/ProfileReader.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace MCCFMD.Serialization
|
||||
{
|
||||
internal class ProfileReader
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user