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
@@ -17,22 +17,30 @@ namespace CliFx
|
|||||||
/// Whether debug mode is allowed in this application.
|
/// Whether debug mode is allowed in this application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDebugModeAllowed { get; }
|
public bool IsDebugModeAllowed { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether preview mode is allowed in this application.
|
/// Whether preview mode is allowed in this application.
|
||||||
/// </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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,8 +125,19 @@ namespace CliFx
|
|||||||
// Debug mode
|
// Debug mode
|
||||||
if (_configuration.IsDebugModeAllowed && input.IsDebugDirectiveSpecified)
|
if (_configuration.IsDebugModeAllowed && input.IsDebugDirectiveSpecified)
|
||||||
{
|
{
|
||||||
// Ensure debugger is attached and continue
|
if (_configuration.PromptDebuggerLaunchInDebugMode)
|
||||||
await WaitForDebuggerAsync();
|
{
|
||||||
|
// Prompt debugger launcher dialog
|
||||||
|
if (!Debugger.IsAttached)
|
||||||
|
{
|
||||||
|
Debugger.Launch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Ensure debugger is attached and continue
|
||||||
|
await WaitForDebuggerAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preview mode
|
// Preview mode
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user