forked from git-ecosystem/git-credential-manager
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDefaultAccountCommand.cs
More file actions
58 lines (47 loc) · 1.75 KB
/
DefaultAccountCommand.cs
File metadata and controls
58 lines (47 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Collections.Generic;
using System.CommandLine;
using System.Threading;
using System.Threading.Tasks;
using GitCredentialManager.UI.ViewModels;
namespace GitCredentialManager.UI.Commands;
public abstract class DefaultAccountCommand : HelperCommand
{
protected DefaultAccountCommand(ICommandContext context)
: base(context, "default-account", "Show prompt to confirm use of the default OS account.")
{
var title = new Option<string>("--title", "Window title (optional).");
AddOption(title);
var userName = new Option<string>("--username", "User name to display.")
{
IsRequired = true
};
AddOption(userName);
var noLogo = new Option<bool>("--no-logo", "Hide the Git Credential Manager logo and logotype.");
AddOption(noLogo);
this.SetHandler(ExecuteAsync, title, userName, noLogo);
}
private async Task<int> ExecuteAsync(string title, string userName, bool noLogo)
{
var viewModel = new DefaultAccountViewModel(Context.SessionManager)
{
Title = !string.IsNullOrWhiteSpace(title)
? title
: "Git Credential Manager",
UserName = userName,
ShowProductHeader = !noLogo
};
await ShowAsync(viewModel, CancellationToken.None);
if (!viewModel.WindowResult)
{
throw new Trace2Exception(Context.Trace2, "User cancelled dialog.");
}
WriteResult(
new Dictionary<string, string>
{
["use_default_account"] = viewModel.UseDefaultAccount ? "1" : "0"
}
);
return 0;
}
protected abstract Task ShowAsync(DefaultAccountViewModel viewModel, CancellationToken ct);
}