From fdc946a9e4f9d2f22dae1dce5df2f2edfaf62c5e Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Fri, 22 Mar 2024 17:34:16 -0700 Subject: [PATCH 1/2] Version bump and package tags --- Source/v2/Meadow.Cli/Meadow.CLI.csproj | 4 ++-- Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/v2/Meadow.Cli/Meadow.CLI.csproj b/Source/v2/Meadow.Cli/Meadow.CLI.csproj index 7fd839e0..9e4b0197 100644 --- a/Source/v2/Meadow.Cli/Meadow.CLI.csproj +++ b/Source/v2/Meadow.Cli/Meadow.CLI.csproj @@ -10,12 +10,12 @@ Wilderness Labs, Inc Wilderness Labs, Inc true - 2.0.30.0 + 2.0.31.0 AnyCPU http://developer.wildernesslabs.co/Meadow/Meadow.CLI/ https://github.com/WildernessLabs/Meadow.CLI icon.png - Meadow, Meadow.Foundation, Meadow.CLI + Meadow,Meadow.Foundation,Meadow.CLI,CLI,command,line,interface,device,IoT Command-line interface for Meadow false false diff --git a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs index 4753feb9..95a88769 100644 --- a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs +++ b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs @@ -6,5 +6,5 @@ namespace Meadow.CLI; public static class Constants { - public const string CLI_VERSION = "2.0.30.0"; + public const string CLI_VERSION = "2.0.31.0"; } \ No newline at end of file From 08f93f986b88208a82c42b79628746df010ca04f Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Fri, 22 Mar 2024 17:34:50 -0700 Subject: [PATCH 2/2] Remove unusable arg and return non-zero codes on error --- Source/v2/Meadow.Cli/Program.cs | 41 +++++++++++---------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/Source/v2/Meadow.Cli/Program.cs b/Source/v2/Meadow.Cli/Program.cs index 37b75889..3dd2de56 100644 --- a/Source/v2/Meadow.Cli/Program.cs +++ b/Source/v2/Meadow.Cli/Program.cs @@ -18,31 +18,13 @@ public class Program { - public static async Task Main(string[] args) + public static async Task Main(string[] _) { - var logLevel = LogEventLevel.Information; - var logModifier = args.FirstOrDefault(a => a.Contains("-m")) - ?.Count(x => x == 'm') ?? 0; - - logLevel -= logModifier; - if (logLevel < 0) - { - logLevel = 0; - } - - var outputTemplate = logLevel == LogEventLevel.Verbose - ? "[{Timestamp:HH:mm:ss.fff} {Level:u3}] {Message:lj}{NewLine}{Exception}" - : "{Message:lj}{NewLine}{Exception}"; + var outputTemplate = "{Message:lj}{NewLine}{Exception}"; Log.Logger = new LoggerConfiguration().MinimumLevel.Verbose() - .WriteTo.Console(logLevel, outputTemplate) + .WriteTo.Console(LogEventLevel.Information, outputTemplate) .CreateLogger(); - // Log that we're using a log level other than default of Information - if (logLevel != LogEventLevel.Information) - { - Console.WriteLine($"Using log level {logLevel}"); - } - var services = new ServiceCollection(); services.AddLogging( @@ -89,30 +71,33 @@ public static async Task Main(string[] args) var serviceProvider = services.BuildServiceProvider(); + int returnCode; + try { - await new CliApplicationBuilder() + returnCode = await new CliApplicationBuilder() .AddCommandsFromThisAssembly() .UseTypeActivator(serviceProvider.GetService!) .SetExecutableName("meadow") .Build() .RunAsync(); } + catch (CommandException ce) + { + returnCode = ce.ExitCode; + } catch (Exception ex) { Console.WriteLine($"Operation failed: {ex.Message}"); -#if DEBUG - throw; //debug spew for debug builds -#endif + returnCode = 1; } - Environment.Exit(0); - return 0; + return returnCode; } private static void AddCommandsAsServices(IServiceCollection services) { - var assembly = System.Reflection.Assembly.GetEntryAssembly(); //.GetAssembly(typeof(Program)); + var assembly = System.Reflection.Assembly.GetEntryAssembly(); Trace.Assert(assembly != null); var types = assembly?.GetTypes();