mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Add ability to specify active debugger attachment instead of passive (#61)
This commit is contained in:
committed by
GitHub
parent
082910c968
commit
ac83233dc2
@@ -23,16 +23,24 @@ namespace CliFx
|
||||
/// </summary>
|
||||
public bool IsPreviewModeAllowed { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Prompt debugger launch when application is in debug mode
|
||||
/// </summary>
|
||||
public bool PromptDebuggerLaunchInDebugMode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="ApplicationConfiguration"/>.
|
||||
/// </summary>
|
||||
public ApplicationConfiguration(
|
||||
IReadOnlyList<Type> commandTypes,
|
||||
bool isDebugModeAllowed, bool isPreviewModeAllowed)
|
||||
bool isDebugModeAllowed,
|
||||
bool isPreviewModeAllowed,
|
||||
bool promptDebuggerLaunchInDebugMode)
|
||||
{
|
||||
CommandTypes = commandTypes;
|
||||
IsDebugModeAllowed = isDebugModeAllowed;
|
||||
IsPreviewModeAllowed = isPreviewModeAllowed;
|
||||
PromptDebuggerLaunchInDebugMode = promptDebuggerLaunchInDebugMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,10 +124,21 @@ namespace CliFx
|
||||
|
||||
// Debug mode
|
||||
if (_configuration.IsDebugModeAllowed && input.IsDebugDirectiveSpecified)
|
||||
{
|
||||
if (_configuration.PromptDebuggerLaunchInDebugMode)
|
||||
{
|
||||
// Prompt debugger launcher dialog
|
||||
if (!Debugger.IsAttached)
|
||||
{
|
||||
Debugger.Launch();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure debugger is attached and continue
|
||||
await WaitForDebuggerAsync();
|
||||
}
|
||||
}
|
||||
|
||||
// Preview mode
|
||||
if (_configuration.IsPreviewModeAllowed && input.IsPreviewDirectiveSpecified)
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace CliFx
|
||||
private readonly HashSet<Type> _commandTypes = new HashSet<Type>();
|
||||
|
||||
private bool _isDebugModeAllowed = true;
|
||||
private bool _promptDebuggerLaunch = false;
|
||||
private bool _isPreviewModeAllowed = true;
|
||||
private string? _title;
|
||||
private string? _executableName;
|
||||
@@ -78,9 +79,10 @@ namespace CliFx
|
||||
/// <summary>
|
||||
/// Specifies whether debug mode (enabled with [debug] directive) is allowed in the application.
|
||||
/// </summary>
|
||||
public CliApplicationBuilder AllowDebugMode(bool isAllowed = true)
|
||||
public CliApplicationBuilder AllowDebugMode(bool isAllowed = true, bool promptDebuggerLaunch = false)
|
||||
{
|
||||
_isDebugModeAllowed = isAllowed;
|
||||
_promptDebuggerLaunch = promptDebuggerLaunch;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -166,7 +168,7 @@ namespace CliFx
|
||||
_typeActivator ??= new DefaultTypeActivator();
|
||||
|
||||
var metadata = new ApplicationMetadata(_title, _executableName, _versionText, _description);
|
||||
var configuration = new ApplicationConfiguration(_commandTypes.ToArray(), _isDebugModeAllowed, _isPreviewModeAllowed);
|
||||
var configuration = new ApplicationConfiguration(_commandTypes.ToArray(), _isDebugModeAllowed, _isPreviewModeAllowed, _promptDebuggerLaunch);
|
||||
|
||||
return new CliApplication(metadata, configuration, _console, _typeActivator);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user