Skip to content

Commit 8852047

Browse files
committed
winui: extract cmdline util methods
Extract shared command line parsing methods used in Windows UI helpers.
1 parent c8643f6 commit 8852047

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/windows/GitHub.UI.Windows/Program.cs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public static void Main(string[] args)
3636

3737
if (StringComparer.OrdinalIgnoreCase.Equals(args[0], "prompt"))
3838
{
39-
string enterpriseUrl = GetParameter(args, "--enterprise-url");
40-
bool basic = TryGetSwitch(args, "--basic");
41-
bool oauth = TryGetSwitch(args, "--oauth");
39+
string enterpriseUrl = CommandLineUtils.GetParameter(args, "--enterprise-url");
40+
bool basic = CommandLineUtils.TryGetSwitch(args, "--basic");
41+
bool oauth = CommandLineUtils.TryGetSwitch(args, "--oauth");
4242

4343
if (!basic && !oauth)
4444
{
@@ -71,7 +71,7 @@ public static void Main(string[] args)
7171
}
7272
else if (StringComparer.OrdinalIgnoreCase.Equals(args[0], "2fa"))
7373
{
74-
bool isSms = TryGetSwitch(args, "--sms");
74+
bool isSms = CommandLineUtils.TryGetSwitch(args, "--sms");
7575

7676
if (!prompts.ShowAuthenticationCodePrompt(isSms, out string authCode))
7777
{
@@ -111,22 +111,5 @@ private static bool TryGetParentWindowHandle(out IntPtr hwnd)
111111
hwnd = default(IntPtr);
112112
return false;
113113
}
114-
115-
private static bool TryGetSwitch(string[] args, string name)
116-
{
117-
return args.Any(arg => StringComparer.OrdinalIgnoreCase.Equals(arg, name));
118-
}
119-
120-
private static string GetParameter(string[] args, string name)
121-
{
122-
int index = Array.FindIndex(args, x => StringComparer.OrdinalIgnoreCase.Equals(x, name));
123-
124-
if (-1 < index && index + 1 < args.Length)
125-
{
126-
return args[index + 1];
127-
}
128-
129-
return null;
130-
}
131114
}
132115
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
using System;
4+
using System.Linq;
5+
6+
namespace Microsoft.Git.CredentialManager.UI
7+
{
8+
public static class CommandLineUtils
9+
{
10+
public static bool TryGetSwitch(string[] args, string name)
11+
{
12+
return args.Any(arg => StringComparer.OrdinalIgnoreCase.Equals(arg, name));
13+
}
14+
15+
public static string GetParameter(string[] args, string name)
16+
{
17+
int index = Array.FindIndex(args, x => StringComparer.OrdinalIgnoreCase.Equals(x, name));
18+
19+
if (-1 < index && index + 1 < args.Length)
20+
{
21+
return args[index + 1];
22+
}
23+
24+
return null;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)