-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathStartOptions.cs
More file actions
73 lines (59 loc) · 3.18 KB
/
StartOptions.cs
File metadata and controls
73 lines (59 loc) · 3.18 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.IO.Abstractions;
using Azure.DataApiBuilder.Config;
using Azure.DataApiBuilder.Product;
using Cli.Constants;
using CommandLine;
using Microsoft.Extensions.Logging;
using static Cli.Utils;
namespace Cli.Commands
{
/// <summary>
/// Start command options
/// </summary>
[Verb("start", isDefault: false, HelpText = "Start Data Api Builder Engine", Hidden = false)]
public class StartOptions : Options
{
private const string LOGLEVEL_HELPTEXT = "Specifies logging level as provided value. For possible values, see: https://go.microsoft.com/fwlink/?linkid=2263106";
public LogBuffer CliBuffer { get; }
public StartOptions(bool verbose, LogLevel? logLevel, bool isHttpsRedirectionDisabled, bool mcpStdio, string? mcpRole, string config)
: base(config)
{
// When verbose is true we set LogLevel to information.
LogLevel = verbose is true ? Microsoft.Extensions.Logging.LogLevel.Information : logLevel;
IsHttpsRedirectionDisabled = isHttpsRedirectionDisabled;
McpStdio = mcpStdio;
McpRole = mcpRole;
CliBuffer = new LogBuffer();
}
// SetName defines mutually exclusive sets, ie: can not have
// both verbose and LogLevel.
[Option("verbose", SetName = "verbose", Required = false, HelpText = "Specifies logging level as informational.")]
public bool Verbose { get; }
[Option("LogLevel", SetName = "LogLevel", Required = false, HelpText = LOGLEVEL_HELPTEXT)]
public LogLevel? LogLevel { get; }
[Option("no-https-redirect", Required = false, HelpText = "Disables automatic https redirects.")]
public bool IsHttpsRedirectionDisabled { get; }
[Option("mcp-stdio", Required = false, HelpText = "Run Data API Builder in MCP stdio mode while starting the engine.")]
public bool McpStdio { get; }
[Value(0, MetaName = "role", Required = false, HelpText = "Optional MCP permissions role, e.g. role:anonymous. If omitted, defaults to anonymous.")]
public string? McpRole { get; }
public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem)
{
CliBuffer.BufferLog(Microsoft.Extensions.Logging.LogLevel.Information, $"{PRODUCT_NAME} {ProductInfo.GetProductVersion()}");
bool isSuccess = ConfigGenerator.TryStartEngineWithOptions(this, loader, fileSystem);
if (!isSuccess)
{
// Update loggers and flush buffers to ensure that all the logs are printed if the TryStartEngineWithOptions fails.
logger = Utils.LoggerFactoryForCli.CreateLogger<Program>();
loader.SetLogger(Utils.LoggerFactoryForCli.CreateLogger<FileSystemRuntimeConfigLoader>());
CliBuffer.FlushToLogger(logger);
loader.FlushLogBuffer();
logger.LogError("Failed to start the engine{mode}.",
McpStdio ? " in MCP stdio mode" : string.Empty);
}
return isSuccess ? CliReturnCode.SUCCESS : CliReturnCode.GENERAL_ERROR;
}
}
}