This repository has been archived by the owner on Dec 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TryGetWorkspaceId() and TryGetLiveMode()
- Loading branch information
1 parent
cecc4b9
commit ae9b30e
Showing
2 changed files
with
15 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
namespace System.CommandLine; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace System.CommandLine; | ||
|
||
/// <summary> | ||
/// Extensions for <see cref="InvocationContext"/> | ||
/// </summary> | ||
internal static class InvocationContextExtensions | ||
{ | ||
public static bool IsVerboseEnabled(this InvocationContext context) | ||
{ | ||
return context.ParseResult.ValueForOption<bool>("--verbose"); | ||
} | ||
public static bool IsVerboseEnabled(this InvocationContext context) => context.ParseResult.ValueForOption<bool>("--verbose"); | ||
public static bool IsTelemetryDisabled(this InvocationContext context) => context.ParseResult.ValueForOption<bool>("--no-telemetry"); | ||
public static string? GetWorkspaceId(this InvocationContext context) => context.ParseResult.ValueForOption<string>("--workspace"); | ||
public static bool? GetLiveMode(this InvocationContext context) => context.ParseResult.ValueForOption<bool?>("--live"); | ||
|
||
public static string? GetWorkspaceId(this InvocationContext context) | ||
public static bool TryGetWorkspaceId(this InvocationContext context, [NotNullWhen(true)] out string? workspaceId) | ||
{ | ||
return context.ParseResult.ValueForOption<string>("--workspace"); | ||
workspaceId = context.GetWorkspaceId(); | ||
return !string.IsNullOrWhiteSpace(workspaceId); | ||
} | ||
|
||
public static bool? GetLiveMode(this InvocationContext context) | ||
public static bool TryGetLiveMode(this InvocationContext context, [NotNullWhen(true)] out bool? liveMode) | ||
{ | ||
return context.ParseResult.ValueForOption<bool?>("--live"); | ||
liveMode = context.GetLiveMode(); | ||
return liveMode is not null; | ||
} | ||
} |