-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathPluginCommandHandler.cs
More file actions
53 lines (49 loc) · 1.71 KB
/
PluginCommandHandler.cs
File metadata and controls
53 lines (49 loc) · 1.71 KB
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
49
50
51
52
53
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Hidi.Options;
namespace Microsoft.OpenApi.Hidi.Handlers
{
internal class PluginCommandHandler : AsynchronousCommandLineAction
{
public CommandOptions CommandOptions { get; }
public PluginCommandHandler(CommandOptions commandOptions)
{
CommandOptions = commandOptions;
}
public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken = default)
{
var hidiOptions = new HidiOptions(parseResult, CommandOptions);
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
var logger = loggerFactory.CreateLogger<PluginCommandHandler>();
try
{
await OpenApiService.PluginManifestAsync(hidiOptions, logger, cancellationToken).ConfigureAwait(false);
return 0;
}
#if RELEASE
#pragma warning disable CA1031 // Do not catch general exception types
#endif
catch (Exception ex)
{
#if DEBUG
logger.LogCritical(ex, "Command failed");
throw; // so debug tools go straight to the source of the exception when attached
#else
#pragma warning disable CA2254
logger.LogCritical(ex.Message);
#pragma warning restore CA2254
return 1;
#endif
}
#if RELEASE
#pragma warning restore CA1031 // Do not catch general exception types
#endif
}
}
}