Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update System.CommandLine to latest version #1265

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/shared/Atlassian.Bitbucket/UI/Commands/CredentialsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ public abstract class CredentialsCommand : HelperCommand
protected CredentialsCommand(ICommandContext context)
: base(context, "prompt", "Show authentication prompt.")
{
AddOption(
new Option<string>("--url", "Bitbucket Server or Data Center URL")
);
var url = new Option<Uri>("--url", "Bitbucket Server or Data Center URL");
AddOption(url);

AddOption(
new Option<string>("--username", "Username or email.")
);
var userName = new Option<string>("--username", "Username or email.");
AddOption(userName);

AddOption(
new Option("--show-oauth", "Show OAuth option.")
);
var oauth = new Option<bool>("--show-oauth", "Show OAuth option.");
AddOption(oauth);

AddOption(
new Option("--show-basic", "Show username/password option.")
);
var basic = new Option<bool>("--show-basic", "Show username/password option.");
AddOption(basic);

Handler = CommandHandler.Create<Uri, string, bool, bool>(ExecuteAsync);
this.SetHandler(ExecuteAsync, url, userName, oauth, basic);
}

private async Task<int> ExecuteAsync(Uri url, string userName, bool showOAuth, bool showBasic)
Expand Down
6 changes: 3 additions & 3 deletions src/shared/Core/Commands/ConfigurationCommands.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading.Tasks;

namespace GitCredentialManager.Commands
Expand All @@ -15,9 +14,10 @@ protected ConfigurationCommandBase(ICommandContext context, string name, string
Context = context;
ConfigurationService = configurationService;

AddOption(new Option<bool>("--system", "Modify the system-wide Git configuration instead of the current user"));
var system = new Option<bool>("--system", "Modify the system-wide Git configuration instead of the current user");
AddOption(system);

Handler = CommandHandler.Create<bool>(ExecuteAsync);
this.SetHandler(ExecuteAsync, system);
}

protected ICommandContext Context { get; }
Expand Down
9 changes: 3 additions & 6 deletions src/shared/Core/Commands/DiagnoseCommand.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using GitCredentialManager.Diagnostics;
Expand Down Expand Up @@ -34,11 +32,10 @@ public DiagnoseCommand(ICommandContext context)
new MicrosoftAuthenticationDiagnostic(context)
};

AddOption(
new Option<string>(new []{"--output", "-o"}, "Output directory for diagnostic logs.")
);
var output = new Option<string>(new[] { "--output", "-o" }, "Output directory for diagnostic logs.");
AddOption(output);

Handler = CommandHandler.Create<string>(ExecuteAsync);
this.SetHandler(ExecuteAsync, output);
}

public void AddDiagnostic(IDiagnostic diagnostic)
Expand Down
3 changes: 1 addition & 2 deletions src/shared/Core/Commands/GitCommandBase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading.Tasks;

namespace GitCredentialManager.Commands
Expand All @@ -23,7 +22,7 @@ protected GitCommandBase(ICommandContext context, string name, string descriptio
Context = context;
_hostProviderRegistry = hostProviderRegistry;

Handler = CommandHandler.Create(ExecuteAsync);
this.SetHandler(ExecuteAsync);
}

protected ICommandContext Context { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/shared/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Identity.Client" Version="4.52.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.28.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21216.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Avalonia" Version="11.0.0-preview6" />
<PackageReference Include="Avalonia.Skia" Version="11.0.0-preview6" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0-preview6" />
Expand Down
48 changes: 17 additions & 31 deletions src/shared/Core/UI/Commands/CredentialsCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
using GitCredentialManager.UI.ViewModels;
Expand All @@ -13,52 +11,40 @@ public abstract class CredentialsCommand : HelperCommand
protected CredentialsCommand(ICommandContext context)
: base(context, "basic", "Show basic authentication prompt.")
{
AddOption(
new Option<string>("--title", "Window title (optional).")
);
var title = new Option<string>("--title", "Window title (optional).");
AddOption(title);

AddOption(
new Option<string>("--resource", "Resource name or URL (optional).")
);
var resource = new Option<string>("--resource", "Resource name or URL (optional).");
AddOption(resource);

AddOption(
new Option<string>("--username", "User name (optional).")
);
var userName = new Option<string>("--username", "User name (optional).");
AddOption(userName);

AddOption(
new Option("--no-logo", "Hide the Git Credential Manager logo and logotype.")
);
var noLogo = new Option<bool>("--no-logo", "Hide the Git Credential Manager logo and logotype.");
AddOption(noLogo);

Handler = CommandHandler.Create<CommandOptions>(ExecuteAsync);
}

private class CommandOptions
{
public string Title { get; set; }
public string Resource { get; set; }
public string UserName { get; set; }
public bool NoLogo { get; set; }
this.SetHandler(ExecuteAsync, title, resource, userName, noLogo);
}

private async Task<int> ExecuteAsync(CommandOptions options)
private async Task<int> ExecuteAsync(string title, string resource, string userName, bool noLogo)
{
var viewModel = new CredentialsViewModel();

if (!string.IsNullOrWhiteSpace(options.Title))
if (!string.IsNullOrWhiteSpace(title))
{
viewModel.Title = options.Title;
viewModel.Title = title;
}

viewModel.Description = !string.IsNullOrWhiteSpace(options.Resource)
? $"Enter your credentials for '{options.Resource}'"
viewModel.Description = !string.IsNullOrWhiteSpace(resource)
? $"Enter your credentials for '{resource}'"
: "Enter your credentials";

if (!string.IsNullOrWhiteSpace(options.UserName))
if (!string.IsNullOrWhiteSpace(userName))
{
viewModel.UserName = options.UserName;
viewModel.UserName = userName;
}

viewModel.ShowProductHeader = !options.NoLogo;
viewModel.ShowProductHeader = !noLogo;

await ShowAsync(viewModel, CancellationToken.None);

Expand Down
41 changes: 15 additions & 26 deletions src/shared/Core/UI/Commands/DefaultAccountCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
using GitCredentialManager.UI.ViewModels;
Expand All @@ -12,40 +11,30 @@ public abstract class DefaultAccountCommand : HelperCommand
protected DefaultAccountCommand(ICommandContext context)
: base(context, "default-account", "Show prompt to confirm use of the default OS account.")
{
AddOption(
new Option<string>("--title", "Window title (optional).")
);

AddOption(
new Option<string>("--username", "User name to display.")
{
IsRequired = true
}
);
var title = new Option<string>("--title", "Window title (optional).");
AddOption(title);

AddOption(
new Option("--no-logo", "Hide the Git Credential Manager logo and logotype.")
);
var userName = new Option<string>("--username", "User name to display.")
{
IsRequired = true
};
AddOption(userName);

Handler = CommandHandler.Create(ExecuteAsync);
}
var noLogo = new Option<bool>("--no-logo", "Hide the Git Credential Manager logo and logotype.");
AddOption(noLogo);

private class CommandOptions
{
public string Title { get; set; }
public string UserName { get; set; }
public bool NoLogo { get; set; }
this.SetHandler(ExecuteAsync, title, userName, noLogo);
}

private async Task<int> ExecuteAsync(CommandOptions options)
private async Task<int> ExecuteAsync(string title, string userName, bool noLogo)
{
var viewModel = new DefaultAccountViewModel(Context.Environment)
{
Title = !string.IsNullOrWhiteSpace(options.Title)
? options.Title
Title = !string.IsNullOrWhiteSpace(title)
? title
: "Git Credential Manager",
UserName = options.UserName,
ShowProductHeader = !options.NoLogo
UserName = userName,
ShowProductHeader = !noLogo
};

await ShowAsync(viewModel, CancellationToken.None);
Expand Down
19 changes: 7 additions & 12 deletions src/shared/Core/UI/Commands/DeviceCodeCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
using GitCredentialManager.UI.ViewModels;
Expand All @@ -12,19 +10,16 @@ public abstract class DeviceCodeCommand : HelperCommand
protected DeviceCodeCommand(ICommandContext context)
: base(context, "device", "Show device code prompt.")
{
AddOption(
new Option<string>("--code", "User code.")
);
var code = new Option<string>("--code", "User code.");
AddOption(code);

AddOption(
new Option<string>("--url", "Verification URL.")
);
var url =new Option<string>("--url", "Verification URL.");
AddOption(url);

AddOption(
new Option("--no-logo", "Hide the Git Credential Manager logo and logotype.")
);
var noLogo = new Option<bool>("--no-logo", "Hide the Git Credential Manager logo and logotype.");
AddOption(noLogo);

Handler = CommandHandler.Create<string, string, bool>(ExecuteAsync);
this.SetHandler(ExecuteAsync, code, url, noLogo);
}

private async Task<int> ExecuteAsync(string code, string url, bool noLogo)
Expand Down
53 changes: 19 additions & 34 deletions src/shared/Core/UI/Commands/OAuthCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
using GitCredentialManager.Authentication;
Expand All @@ -14,54 +13,40 @@ public abstract class OAuthCommand : HelperCommand
protected OAuthCommand(ICommandContext context)
: base(context, "oauth", "Show OAuth authentication prompt.")
{
AddOption(
new Option<string>("--title", "Window title (optional).")
);
var title = new Option<string>("--title", "Window title (optional).");
AddOption(title);

AddOption(
new Option<string>("--resource", "Resource name or URL (optional).")
);
var resource = new Option<string>("--resource", "Resource name or URL (optional).");
AddOption(resource);

AddOption(
new Option("--browser", "Show browser authentication option.")
);
var browser = new Option<bool>("--browser", "Show browser authentication option.");
AddOption(browser);

AddOption(
new Option("--device-code", "Show device code authentication option.")
);
var deviceCode = new Option<bool>("--device-code", "Show device code authentication option.");
AddOption(deviceCode);

AddOption(
new Option("--no-logo", "Hide the Git Credential Manager logo and logotype.")
);
var noLogo = new Option<bool>("--no-logo", "Hide the Git Credential Manager logo and logotype.");
AddOption(noLogo);

Handler = CommandHandler.Create<CommandOptions>(ExecuteAsync);
this.SetHandler(ExecuteAsync, title, resource, browser, deviceCode, noLogo);
}

private class CommandOptions
{
public string Title { get; set; }
public string Resource { get; set; }
public bool Browser { get; set; }
public bool DeviceCode { get; set; }
public bool NoLogo { get; set; }
}

private async Task<int> ExecuteAsync(CommandOptions options)
private async Task<int> ExecuteAsync(string title, string resource, bool browser, bool deviceCode, bool noLogo)
{
var viewModel = new OAuthViewModel();

if (!string.IsNullOrWhiteSpace(options.Title))
if (!string.IsNullOrWhiteSpace(title))
{
viewModel.Title = options.Title;
viewModel.Title = title;
}

viewModel.Description = !string.IsNullOrWhiteSpace(options.Resource)
? $"Sign in to '{options.Resource}'"
viewModel.Description = !string.IsNullOrWhiteSpace(resource)
? $"Sign in to '{resource}'"
: "Select a sign-in option";

viewModel.ShowBrowserLogin = options.Browser;
viewModel.ShowDeviceCodeLogin = options.DeviceCode;
viewModel.ShowProductHeader = !options.NoLogo;
viewModel.ShowBrowserLogin = browser;
viewModel.ShowDeviceCodeLogin = deviceCode;
viewModel.ShowProductHeader = !noLogo;

await ShowAsync(viewModel, CancellationToken.None);

Expand Down
Loading