-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (53 loc) · 1.94 KB
/
Program.cs
File metadata and controls
65 lines (53 loc) · 1.94 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
59
60
61
62
63
64
65
using System.Text.Json;
using LibraryAzureDevOps;
using Microsoft.Extensions.Configuration;
using Spectre.Console;
await Main(args);
return;
static async Task Main(string[] args)
{
var settings = LoadSettings();
var variablesResponse = await FetchVariablesResponseAsync(settings);
var variableGroups = DeserializeVariableGroups(variablesResponse);
var variableGroupService = new VariableGroupService(settings);
var searchGroupName = PromptForGroupName(settings);
var variableGroupFound = FilterVariableGroups(variableGroups, searchGroupName);
variableGroupService.WriteVariableGroups(variableGroupFound);
if (variableGroupFound.Any())
{
var searchKey = AnsiConsole.Ask<string>("[blue]What variable are you looking for?[/]");
variableGroupService.WriteVariables(variableGroupFound, searchKey);
}
}
static Settings LoadSettings()
{
var builder = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.Development.json", optional: false, reloadOnChange: true);
return builder.Build()
.GetSection("Settings")
.Get<Settings>()!;
}
static async Task<string> FetchVariablesResponseAsync(Settings settings)
{
var api = new AzureDevOpsApi(settings);
return await api.GetLibraries();
}
static List<VariableGroup> DeserializeVariableGroups(string variablesResponse)
{
return JsonSerializer.Deserialize<List<VariableGroup>>(variablesResponse)
?? new List<VariableGroup>();
}
static string PromptForGroupName(Settings settings)
{
return AnsiConsole.Prompt(
new TextPrompt<string>("[blue]What's your group?[/]")
.DefaultValue(settings.DefaultGroup)
);
}
static List<VariableGroup> FilterVariableGroups(List<VariableGroup> variableGroups, string searchGroupName)
{
return variableGroups
.Where(x => x.Name.Contains(searchGroupName, StringComparison.OrdinalIgnoreCase))
.ToList();
}