Add ability to specify active debugger attachment instead of passive (#61)

This commit is contained in:
Volodymyr Shkolka
2020-07-10 13:54:09 +03:00
committed by GitHub
parent 082910c968
commit ac83233dc2
3 changed files with 27 additions and 6 deletions

View File

@@ -23,16 +23,24 @@ namespace CliFx
/// </summary> /// </summary>
public bool IsPreviewModeAllowed { get; } public bool IsPreviewModeAllowed { get; }
/// <summary>
/// Prompt debugger launch when application is in debug mode
/// </summary>
public bool PromptDebuggerLaunchInDebugMode { get; }
/// <summary> /// <summary>
/// Initializes an instance of <see cref="ApplicationConfiguration"/>. /// Initializes an instance of <see cref="ApplicationConfiguration"/>.
/// </summary> /// </summary>
public ApplicationConfiguration( public ApplicationConfiguration(
IReadOnlyList<Type> commandTypes, IReadOnlyList<Type> commandTypes,
bool isDebugModeAllowed, bool isPreviewModeAllowed) bool isDebugModeAllowed,
bool isPreviewModeAllowed,
bool promptDebuggerLaunchInDebugMode)
{ {
CommandTypes = commandTypes; CommandTypes = commandTypes;
IsDebugModeAllowed = isDebugModeAllowed; IsDebugModeAllowed = isDebugModeAllowed;
IsPreviewModeAllowed = isPreviewModeAllowed; IsPreviewModeAllowed = isPreviewModeAllowed;
PromptDebuggerLaunchInDebugMode = promptDebuggerLaunchInDebugMode;
} }
} }
} }

View File

@@ -124,10 +124,21 @@ namespace CliFx
// Debug mode // Debug mode
if (_configuration.IsDebugModeAllowed && input.IsDebugDirectiveSpecified) if (_configuration.IsDebugModeAllowed && input.IsDebugDirectiveSpecified)
{
if (_configuration.PromptDebuggerLaunchInDebugMode)
{
// Prompt debugger launcher dialog
if (!Debugger.IsAttached)
{
Debugger.Launch();
}
}
else
{ {
// Ensure debugger is attached and continue // Ensure debugger is attached and continue
await WaitForDebuggerAsync(); await WaitForDebuggerAsync();
} }
}
// Preview mode // Preview mode
if (_configuration.IsPreviewModeAllowed && input.IsPreviewDirectiveSpecified) if (_configuration.IsPreviewModeAllowed && input.IsPreviewDirectiveSpecified)

View File

@@ -16,6 +16,7 @@ namespace CliFx
private readonly HashSet<Type> _commandTypes = new HashSet<Type>(); private readonly HashSet<Type> _commandTypes = new HashSet<Type>();
private bool _isDebugModeAllowed = true; private bool _isDebugModeAllowed = true;
private bool _promptDebuggerLaunch = false;
private bool _isPreviewModeAllowed = true; private bool _isPreviewModeAllowed = true;
private string? _title; private string? _title;
private string? _executableName; private string? _executableName;
@@ -78,9 +79,10 @@ namespace CliFx
/// <summary> /// <summary>
/// Specifies whether debug mode (enabled with [debug] directive) is allowed in the application. /// Specifies whether debug mode (enabled with [debug] directive) is allowed in the application.
/// </summary> /// </summary>
public CliApplicationBuilder AllowDebugMode(bool isAllowed = true) public CliApplicationBuilder AllowDebugMode(bool isAllowed = true, bool promptDebuggerLaunch = false)
{ {
_isDebugModeAllowed = isAllowed; _isDebugModeAllowed = isAllowed;
_promptDebuggerLaunch = promptDebuggerLaunch;
return this; return this;
} }
@@ -166,7 +168,7 @@ namespace CliFx
_typeActivator ??= new DefaultTypeActivator(); _typeActivator ??= new DefaultTypeActivator();
var metadata = new ApplicationMetadata(_title, _executableName, _versionText, _description); 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); return new CliApplication(metadata, configuration, _console, _typeActivator);
} }