Add verbose option, bump version correctly.

mac
Miepee 4 years ago
parent fd76a6b6ae
commit 1fed1eb9bf

@ -6,7 +6,7 @@
<RollForward>LatestMajor</RollForward> <RollForward>LatestMajor</RollForward>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<RootNamespace>AM2RPortHelper</RootNamespace> <RootNamespace>AM2RPortHelper</RootNamespace>
<InformationalVersion>1.3.0</InformationalVersion> <InformationalVersion>1.4.0</InformationalVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

@ -1,6 +1,11 @@
using System; using System;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Help;
using System.CommandLine.Parsing;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AM2RPortHelperLib; using AM2RPortHelperLib;
namespace AM2RPortHelper; namespace AM2RPortHelper;
@ -9,21 +14,23 @@ namespace AM2RPortHelper;
internal static class Program internal static class Program
{ {
// TODO: implement launcher flag -u launcher // TODO: implement launcher flag -u launcher
private static void OutputHandlerDelegate(string output) => Console.WriteLine(output);
private static int Main(string[] args) private static int Main(string[] args)
{ {
Console.WriteLine("AM2RPortHelperCLI v" + PortHelper.Version);
//PortHelper.PortLauncherMod("/home/narr/Downloads/Multitroid1_4_2VM_Linux.zip", "Windows", false, "./foo.zip"); //PortHelper.PortLauncherMod("/home/narr/Downloads/Multitroid1_4_2VM_Linux.zip", "Windows", false, "./foo.zip");
var interactiveOption = new Option<bool>(new[] { "-i", "--interactive" }, "Use an interactive mode. This will ignore all other options."); var interactiveOption = new Option<bool>(new[] { "-i", "--interactive" }, "Use an interactive mode. This will ignore all other options.");
var fileOption = new Option<FileInfo>(new[] { "-f", "--file" }, "The file path to the raw mod that should be ported. *REQUIRED*"); var fileOption = new Option<FileInfo>(new[] { "-f", "--file" }, "The file path to the raw mod that should be ported. *REQUIRED IN NON-INTERACTIVE*");
var linuxOption = new Option<FileInfo>(new[] { "-l", "--linux" }, "The output file path for the Linux mod. None given equals to no Linux port."); var linuxOption = new Option<FileInfo>(new[] { "-l", "--linux" }, "The output file path for the Linux mod. None given equals to no Linux port.");
var androidOption = new Option<FileInfo>(new[] { "-a", "--android" }, "The output file path for the Android mod. None given equals to no Android port."); var androidOption = new Option<FileInfo>(new[] { "-a", "--android" }, "The output file path for the Android mod. None given equals to no Android port.");
var macOption = new Option<FileInfo>(new[] { "-m", "--mac" }, "The output file path for the Mac mod. None given equals to no Mac port."); var macOption = new Option<FileInfo>(new[] { "-m", "--mac" }, "The output file path for the Mac mod. None given equals to no Mac port.");
var nameOption = new Option<string>(new[] { "-n", "--name" }, "The name used for the Mac or Android mod. Required for the Mac option, and optional for the Android version. Has no effect on anything else."); var nameOption = new Option<string>(new[] { "-n", "--name" }, "The name used for the Mac or Android mod. Required for the Mac option, and optional for the Android version. Has no effect on anything else.");
var internetOption = new Option<bool>(new[] { "-w", "--internet" }, "Add internet usage permissions to the Android mod. Has no effect to other OS."); var internetOption = new Option<bool>(new[] { "-w", "--internet" }, "Add internet usage permissions to the Android mod. Has no effect to other OS.");
var verboseOption = new Option<bool>(new[] { "-v", "--verbose" }, "Whether to show verbose output.");
RootCommand rootCommand = new RootCommand RootCommand rootCommand = new RootCommand("A utility to port Windows AM2R Mods to other operating systems.")
{ {
interactiveOption, interactiveOption,
fileOption, fileOption,
@ -33,10 +40,17 @@ internal static class Program
nameOption, nameOption,
internetOption internetOption
}; };
rootCommand.SetHandler(RootMethod, interactiveOption, fileOption, linuxOption, androidOption, macOption, nameOption, internetOption); rootCommand.SetHandler(RootMethod, interactiveOption, fileOption, linuxOption, androidOption,
macOption, nameOption, internetOption, verboseOption);
return rootCommand.Invoke(args); var parser = new CommandLineBuilder(rootCommand)
.UseDefaults()
.UseHelp(ctx => { ctx.HelpBuilder.CustomizeLayout(_ => HelpBuilder.Default.GetLayout().Prepend(_ => Console.WriteLine("AM2RPortHelperCLI v" + PortHelper.Version)));})
.Build();
return parser.Invoke(args);
//return rootCommand.Invoke(args);
/* /*
TODO: show this somewhere? maybe? TODO: show this somewhere? maybe?
@ -45,37 +59,47 @@ internal static class Program
*/ */
} }
private static void RootMethod(bool interactive, FileInfo inputModPath, FileInfo linuxPath, FileInfo androidPath, FileInfo macPath, string modName, bool usesInternet) #pragma warning disable CS1998
private static async Task<int> RootMethod(bool interactive, FileInfo inputModPath, FileInfo linuxPath, FileInfo androidPath, FileInfo macPath,
string modName, bool usesInternet, bool beVerbose)
#pragma warning restore CS1998
{ {
if (interactive || beVerbose)
Console.WriteLine("AM2RPortHelperCLI v" + PortHelper.Version);
if (interactive) if (interactive)
{ {
RunInteractive(); RunInteractive();
return; return 0;
} }
if (!IsValidInputZip(inputModPath)) if (!IsValidInputZip(inputModPath))
{ {
Console.Error.WriteLine("Input path does not exist, or does not point to a zip file!"); Console.Error.WriteLine("Input path does not exist, or does not point to a zip file!");
return; return 1;
} }
if (linuxPath is not null) if (linuxPath is not null)
{ {
PortHelper.PortWindowsToLinux(inputModPath.FullName, linuxPath.FullName); PortHelper.PortWindowsToLinux(inputModPath.FullName, linuxPath.FullName, beVerbose ? OutputHandlerDelegate : null);
} }
if (androidPath is not null) if (androidPath is not null)
{ {
PortHelper.PortWindowsToAndroid(inputModPath.FullName, androidPath.FullName, string.IsNullOrWhiteSpace(modName) ? null : modName, usesInternet); PortHelper.PortWindowsToAndroid(inputModPath.FullName, androidPath.FullName,
String.IsNullOrWhiteSpace(modName) ? null : modName, usesInternet, beVerbose ? OutputHandlerDelegate : null);
} }
if (macPath is not null) if (macPath is not null)
{ {
if (modName is null) if (modName is null)
{ {
Console.Error.WriteLine("Mac option was chosen but mod name was not given!"); Console.Error.WriteLine("Mac option was chosen but mod name was not given!");
return; return 1;
} }
PortHelper.PortWindowsToMac(inputModPath.FullName, macPath.FullName, modName); PortHelper.PortWindowsToMac(inputModPath.FullName, macPath.FullName, modName, beVerbose ? OutputHandlerDelegate : null);
} }
Console.WriteLine("Done."); if (beVerbose)
Console.WriteLine("Done.");
return 0;
} }
private static void RunInteractive() private static void RunInteractive()
{ {
@ -136,7 +160,7 @@ internal static class Program
if (File.Exists(linuxPath)) if (File.Exists(linuxPath))
File.Delete(linuxPath); File.Delete(linuxPath);
PortHelper.PortWindowsToLinux(modZipPath, linuxPath); PortHelper.PortWindowsToLinux(modZipPath, linuxPath, OutputHandlerDelegate);
} }
if (androidSelected) if (androidSelected)
@ -160,7 +184,7 @@ internal static class Program
} }
while (internetSelected == null); while (internetSelected == null);
PortHelper.PortWindowsToAndroid(modZipPath, androidPath, null, internetSelected.Value); PortHelper.PortWindowsToAndroid(modZipPath, androidPath, null, internetSelected.Value, OutputHandlerDelegate);
} }
if (macSelected) if (macSelected)
{ {
@ -169,7 +193,7 @@ internal static class Program
Console.WriteLine("Mac requires a name! Please enter one (no special characters!):"); Console.WriteLine("Mac requires a name! Please enter one (no special characters!):");
string modName = Console.ReadLine(); string modName = Console.ReadLine();
PortHelper.PortWindowsToMac(modZipPath, macPath, modName); PortHelper.PortWindowsToMac(modZipPath, macPath, modName, OutputHandlerDelegate);
} }
Console.WriteLine("Successfully finished!"); Console.WriteLine("Successfully finished!");
@ -182,6 +206,6 @@ internal static class Program
private static bool IsValidInputZip(FileInfo path) private static bool IsValidInputZip(FileInfo path)
{ {
return path is not null && IsValidInputZip(path.FullName); return IsValidInputZip(path?.FullName);
} }
} }

@ -17,10 +17,7 @@ public static partial class PortHelper
private static void SendOutput(string output) private static void SendOutput(string output)
{ {
if (outputHandler is not null) outputHandler?.Invoke(output);
outputHandler.Invoke(output);
else
Console.WriteLine(output);
} }
/// <summary> /// <summary>
@ -429,6 +426,4 @@ public static partial class PortHelper
// Clean up // Clean up
Directory.Delete(baseTempDirectory, true); Directory.Delete(baseTempDirectory, true);
} }
} }
Loading…
Cancel
Save