Skip to content

Commit

Permalink
using non-zero exit code if app gets error
Browse files Browse the repository at this point in the history
  • Loading branch information
am1goo committed Aug 1, 2024
1 parent 64f8187 commit 4569eba
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions SteamMarketeer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@ class Program
+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+
";

private static readonly string _thisName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
private static readonly Version _thisVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

static async Task Main(string[] args)
{
var thisName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
var thisVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

Logger.Log(ASCII_NAME);
Logger.Log($"Version: {thisVersion}");
Logger.Log($"Version: {_thisVersion}");
Logger.Log($"License: MIT");
Logger.Skip();

if (args.Length <= 0 || !uint.TryParse(args[0], out var appId))
{
Logger.Log("The syntax of the command is incorrect.");
Logger.Skip();
Logger.Log($"Usage: {thisName}.exe [APP_ID]");
Logger.Skip();
Logger.Log("APP_ID - it's app id from Steam Store (you can see these numbers in any game url)");
ExitWithCode(ExitCode.InvalidArguments);
return;
}

Expand Down Expand Up @@ -131,5 +127,30 @@ static async Task Main(string[] args)
Console.ReadKey();
#endif
}

private static void PrintHelp()
{
Logger.Log("The syntax of the command is incorrect.");
Logger.Skip();
Logger.Log($"Usage: {_thisName}.exe APP_ID");
Logger.Skip();
Logger.Log("APP_ID - it's app id from Steam Store (you can see these numbers in any game url)");
}

private static void ExitWithCode(ExitCode exitCode)
{
switch (exitCode)
{
case ExitCode.InvalidArguments:
PrintHelp();
break;
}
Environment.Exit((int)exitCode);
}

private enum ExitCode
{
InvalidArguments = 1,
}
}
}

0 comments on commit 4569eba

Please sign in to comment.