made all options optional

This commit is contained in:
Ellpeck 2020-04-09 18:30:30 +02:00
parent b3ce0e118a
commit b6096caf46
2 changed files with 37 additions and 15 deletions

View file

@ -4,9 +4,9 @@ using CommandLine;
namespace GameBundle {
public class Options {
[Option('s', "source", Required = true, HelpText = "The location of the .csproj file that should be built and bundled")]
[Option('s', "source", HelpText = "The location of the .csproj file that should be built and bundled. By default, the current directory is scanned for one")]
public string SourceFile { get; set; }
[Option('o', "output", Required = true, HelpText = "The location of the directory that the bundles should be stored in")]
[Option('o', "output", Default = "bin/Bundled", HelpText = "The location of the directory that the bundles should be stored in")]
public string OutputDirectory { get; set; }
[Option('v', "verbose", Default = false)]
public bool Verbose { get; set; }
@ -22,7 +22,7 @@ namespace GameBundle {
public string[] ExcludedFiles { get; set; }
[Option("32bit", Default = false, HelpText = "Publish for 32 bit instead of 64 bit. Note that this is only possible on Windows")]
public bool Publish32Bit { get; set; }
[Option("trim", Default = true, HelpText = "If the application should be trimmed when being published")]
[Option("trim", Default = true, HelpText = "Trim the application when publishing")]
public bool Trim { get; set; }
}

View file

@ -15,25 +15,31 @@ namespace GameBundle {
if (RunProcess(options, "dotnet", "tool install nulastudio.ncbeauty -g") < 0)
return -1;
var proj = new FileInfo(options.SourceFile);
if (!proj.Exists) {
Console.WriteLine("Project file not found at " + proj.FullName);
var proj = GetProjectFile(options);
if (proj == null || !proj.Exists) {
Console.WriteLine("Project file not found");
return -1;
}
if (options.Verbose)
Console.WriteLine("Found project file at " + proj.FullName);
Console.WriteLine("Bundling project " + proj.FullName);
var bundleDir = new DirectoryInfo(Path.Combine(options.OutputDirectory, "Bundled"));
var bundleDir = new DirectoryInfo(options.OutputDirectory);
if (!bundleDir.Exists)
bundleDir.Create();
if (options.BundleWindows)
if (options.BundleWindows) {
Console.WriteLine("Bundling for windows");
Publish(options, proj, $"{bundleDir}/win", options.Publish32Bit ? "win-x86" : "win-x64");
if (options.BundleLinux)
}
if (options.BundleLinux) {
Console.WriteLine("Bundling for linux");
Publish(options, proj, $"{bundleDir}/linux", "linux-x64");
if (options.BundleMac)
}
if (options.BundleMac) {
Console.WriteLine("Bundling for mac");
Publish(options, proj, $"{bundleDir}/mac", "osx-x64");
}
Console.WriteLine("Done");
return 0;
}
@ -55,11 +61,27 @@ namespace GameBundle {
private static int RunProcess(Options options, string program, string args) {
if (options.Verbose)
Console.WriteLine($"$ {program} {args}");
var process = Process.Start(program, args);
Console.WriteLine($"> {program} {args}");
var info = new ProcessStartInfo(program, args);
if (!options.Verbose)
info.CreateNoWindow = true;
var process = Process.Start(info);
process.WaitForExit();
if (options.Verbose)
Console.WriteLine($"{program} finished with exit code {process.ExitCode}");
return process.ExitCode;
}
private static FileInfo GetProjectFile(Options options) {
if (!string.IsNullOrEmpty(options.SourceFile))
return new FileInfo(options.SourceFile);
var dir = new DirectoryInfo(Environment.CurrentDirectory);
foreach (var file in dir.EnumerateFiles()) {
if (Path.GetExtension(file.FullName).Contains("proj"))
return file;
}
return null;
}
}
}