From b6096caf468e2e2b47c52a0e78de207695251d26 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 9 Apr 2020 18:30:30 +0200 Subject: [PATCH] made all options optional --- GameBundle/Options.cs | 6 +++--- GameBundle/Program.cs | 46 ++++++++++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/GameBundle/Options.cs b/GameBundle/Options.cs index ab3fdf0..8889ed7 100644 --- a/GameBundle/Options.cs +++ b/GameBundle/Options.cs @@ -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; } } diff --git a/GameBundle/Program.cs b/GameBundle/Program.cs index ab770ac..4ce13fb 100644 --- a/GameBundle/Program.cs +++ b/GameBundle/Program.cs @@ -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; + } + } } \ No newline at end of file