-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOptionsFileCreateCommand.cs
48 lines (41 loc) · 1.46 KB
/
OptionsFileCreateCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace Atc.CodingRules.Updater.CLI.Commands;
public class OptionsFileCreateCommand : AsyncCommand<ProjectCommandSettings>
{
private readonly ILogger<OptionsFileCreateCommand> logger;
public OptionsFileCreateCommand(
ILogger<OptionsFileCreateCommand> logger)
=> this.logger = logger;
public override Task<int> ExecuteAsync(
CommandContext context,
ProjectCommandSettings settings)
{
ArgumentNullException.ThrowIfNull(settings);
return ExecuteInternalAsync(settings);
}
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "OK.")]
private async Task<int> ExecuteInternalAsync(
ProjectCommandSettings settings)
{
ConsoleHelper.WriteHeader();
var projectPath = new DirectoryInfo(settings.ProjectPath);
try
{
var (isSuccessful, error) = await OptionsHelper.CreateOptionsFile(projectPath, settings);
if (isSuccessful)
{
logger.LogInformation("The options file is created");
}
else
{
logger.LogError(error);
}
}
catch (Exception ex)
{
logger.LogError($"{EmojisConstants.Error} {ex.GetMessage()}");
return ConsoleExitStatusCodes.Failure;
}
logger.LogInformation($"{EmojisConstants.Success} Done");
return ConsoleExitStatusCodes.Success;
}
}