Skip to content

Commit

Permalink
github: consolidate helper options; add --all option
Browse files Browse the repository at this point in the history
Consolidate all the UI helper options for the GitHub `prompt` view in to
an `Options` class (rather than bloat the execution handler with more
arguments).

Also fix a bug whereby the GitHub host provider would attempt to invoke
the UI helper with an `--all` option when all authentication modes are
available, but no such option is available!

This option was only available on the old WPF UI helper, and was never
carried forward to the Avalonia UI.
  • Loading branch information
mjcheetham committed Oct 6, 2021
1 parent 24356dc commit 0fdb03a
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/shared/GitHub.UI/Commands/CredentialsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,40 @@ protected CredentialsCommand(ICommandContext context)
new Option("--pat", "Enable personal access token authentication.")
);

Handler = CommandHandler.Create<string, string, bool, bool, bool>(ExecuteAsync);
AddOption(
new Option("--all", "Enable all available authentication options.")
);

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

private class CommandOptions
{
public string UserName { get; set; }
public string EnterpriseUrl { get; set; }
public bool Basic { get; set; }
public bool Browser { get; set; }
public bool Pat { get; set; }
public bool All { get; set; }
}

private async Task<int> ExecuteAsync(string enterpriseUrl, string userName, bool basic, bool browser, bool pat)
private async Task<int> ExecuteAsync(CommandOptions options)
{
var viewModel = new CredentialsViewModel(Context.Environment)
{
ShowBrowserLogin = browser,
ShowTokenLogin = pat,
ShowBasicLogin = basic,
ShowBrowserLogin = options.All || options.Browser,
ShowTokenLogin = options.All || options.Pat,
ShowBasicLogin = options.All || options.Basic,
};

if (!GitHubHostProvider.IsGitHubDotCom(enterpriseUrl))
if (!GitHubHostProvider.IsGitHubDotCom(options.EnterpriseUrl))
{
viewModel.EnterpriseUrl = enterpriseUrl;
viewModel.EnterpriseUrl = options.EnterpriseUrl;
}

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

await ShowAsync(viewModel, CancellationToken.None);
Expand Down

0 comments on commit 0fdb03a

Please sign in to comment.