pass return value from command

This commit is contained in:
Caelan Sayler
2024-01-14 16:30:09 +00:00
parent ab488f5520
commit b1b64f5bf7

View File

@@ -17,18 +17,21 @@ public class RunnerFactory
_config = config; _config = config;
} }
public async Task CreateAndExecuteAsync<T>(string commandName, T options) where T : BaseCommand public async Task<int> CreateAndExecuteAsync<T>(string commandName, T options) where T : BaseCommand
{ {
_logger.LogInformation($"[bold]{Program.INTRO}[/]"); _logger.LogInformation($"[bold]{Program.INTRO}[/]");
var runner = await CreateAsync(options); var runner = await CreateAsync(options);
var method = typeof(ICommandRunner).GetMethod(commandName); var method = typeof(ICommandRunner).GetMethod(commandName);
try { try {
await (Task) method.Invoke(runner, new object[] { options }); await (Task) method.Invoke(runner, new object[] { options });
return 0;
} catch (Exception ex) when (ex is ProcessFailedException or UserInfoException) { } catch (Exception ex) when (ex is ProcessFailedException or UserInfoException) {
// some exceptions are just user info / user error, so don't need a stack trace. // some exceptions are just user info / user error, so don't need a stack trace.
_logger.Fatal($"[bold orange3]{ex.Message}[/]"); _logger.Fatal($"[bold orange3]{ex.Message}[/]");
return -1;
} catch (Exception ex) { } catch (Exception ex) {
_logger.Fatal(ex, $"Command {commandName} had an exception."); _logger.Fatal(ex, $"Command {commandName} had an exception.");
return -1;
} }
} }