Skip to content

Commit

Permalink
Platform-agnostic exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-harmoniq committed Aug 6, 2020
1 parent ab88768 commit 1e80d07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
12 changes: 6 additions & 6 deletions CliToolkit.TestApp/CliToolkit.TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition=" '$(RuntimeIdentifier)' != '' ">
<PropertyGroup Condition=" '$(OutputType)' == 'Exe' And '$(Configuration)' == 'Release' ">
<Arch>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</Arch>
<RuntimeIdentifier Condition=" '$([MSBuild]::IsOSPlatform(Windows))' ">win-$(Arch.ToLower())</RuntimeIdentifier>
<RuntimeIdentifier Condition=" '$([MSBuild]::IsOSPlatform(Linux))' ">linux-$(Arch.ToLower())</RuntimeIdentifier>
<RuntimeIdentifier Condition=" '$([MSBuild]::IsOSPlatform(OSX))' ">osx-$(Arch.ToLower())</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>false</SelfContained>
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
<PublishDir>bin</PublishDir>
<PublishDir>$(MSBuildProjectDirectory)\bin</PublishDir>
</PropertyGroup>

<ItemGroup>
Expand All @@ -32,8 +36,4 @@
<ProjectReference Include="..\CliToolkit\CliToolkit.csproj" />
</ItemGroup>

<Target Name="target6" AfterTargets="AfterPublish">
<Delete Files="bin\CliToolkit.pdb" />
</Target>

</Project>
9 changes: 6 additions & 3 deletions CliToolkit/CliApp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CliToolkit.Internal;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace CliToolkit
Expand All @@ -25,13 +26,15 @@ public void Start(string[] args)
catch (CliAppBuilderException ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Failed to initialized the given command.");
Console.WriteLine($"{nameof(CliAppBuilderException)}:");
Console.WriteLine(ex.Message);
}
catch
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
throw;
var exName = ex.GetType().FullName;
Console.WriteLine($"Unhandled exception. {exName}: {ex.Message}");
Console.WriteLine(ex.StackTrace);
}
finally
{
Expand Down
4 changes: 2 additions & 2 deletions CliToolkit/CliCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public CliCommand()
_commandProperties = allProps.GetCommandProperties();
}

public abstract void OnExecute(string[] args);

public void PrintHelpMenu()
{
Console.WriteLine();
Expand Down Expand Up @@ -80,8 +82,6 @@ public void PrintHelpMenu()
}
}

public abstract void OnExecute(string[] args);

internal void Parse(
CliCommand caller,
AppSettings userSettings,
Expand Down

0 comments on commit 1e80d07

Please sign in to comment.