Skip to content

Commit b6742a6

Browse files
committed
Ported working System.CommandLine implementation from existing repo
1 parent e893f23 commit b6742a6

File tree

182 files changed

+8008
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+8008
-0
lines changed

WindowsAppCommunity.CommandLine.sln

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,66 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsAppCommunity.Command
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsAppCommunity.CommandLine.Tests", "tests\WindowsAppCommunity.CommandLine.Tests.csproj", "{296B048C-F31A-4555-AE05-B96F27399907}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sdk", "sdk", "{FF13A09E-0E72-1904-124B-A4E979EF28D3}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7FB99E3F-AC58-B8E3-DDC8-7641B56C22C3}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsAppCommunity.Sdk", "sdk\src\WindowsAppCommunity.Sdk.csproj", "{363E1752-33E4-471A-9FD0-5C1C941EFB2B}"
15+
EndProject
1016
Global
1117
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1218
Debug|Any CPU = Debug|Any CPU
19+
Debug|x64 = Debug|x64
20+
Debug|x86 = Debug|x86
1321
Release|Any CPU = Release|Any CPU
22+
Release|x64 = Release|x64
23+
Release|x86 = Release|x86
1424
EndGlobalSection
1525
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1626
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1727
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Debug|x64.ActiveCfg = Debug|Any CPU
29+
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Debug|x64.Build.0 = Debug|Any CPU
30+
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Debug|x86.ActiveCfg = Debug|Any CPU
31+
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Debug|x86.Build.0 = Debug|Any CPU
1832
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
1933
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Release|x64.ActiveCfg = Release|Any CPU
35+
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Release|x64.Build.0 = Release|Any CPU
36+
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Release|x86.ActiveCfg = Release|Any CPU
37+
{4103C486-827D-4DDC-A600-752D8DD3D6E0}.Release|x86.Build.0 = Release|Any CPU
2038
{296B048C-F31A-4555-AE05-B96F27399907}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2139
{296B048C-F31A-4555-AE05-B96F27399907}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{296B048C-F31A-4555-AE05-B96F27399907}.Debug|x64.ActiveCfg = Debug|Any CPU
41+
{296B048C-F31A-4555-AE05-B96F27399907}.Debug|x64.Build.0 = Debug|Any CPU
42+
{296B048C-F31A-4555-AE05-B96F27399907}.Debug|x86.ActiveCfg = Debug|Any CPU
43+
{296B048C-F31A-4555-AE05-B96F27399907}.Debug|x86.Build.0 = Debug|Any CPU
2244
{296B048C-F31A-4555-AE05-B96F27399907}.Release|Any CPU.ActiveCfg = Release|Any CPU
2345
{296B048C-F31A-4555-AE05-B96F27399907}.Release|Any CPU.Build.0 = Release|Any CPU
46+
{296B048C-F31A-4555-AE05-B96F27399907}.Release|x64.ActiveCfg = Release|Any CPU
47+
{296B048C-F31A-4555-AE05-B96F27399907}.Release|x64.Build.0 = Release|Any CPU
48+
{296B048C-F31A-4555-AE05-B96F27399907}.Release|x86.ActiveCfg = Release|Any CPU
49+
{296B048C-F31A-4555-AE05-B96F27399907}.Release|x86.Build.0 = Release|Any CPU
50+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Debug|x64.ActiveCfg = Debug|Any CPU
53+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Debug|x64.Build.0 = Debug|Any CPU
54+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Debug|x86.ActiveCfg = Debug|Any CPU
55+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Debug|x86.Build.0 = Debug|Any CPU
56+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
57+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Release|x64.ActiveCfg = Release|Any CPU
59+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Release|x64.Build.0 = Release|Any CPU
60+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Release|x86.ActiveCfg = Release|Any CPU
61+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B}.Release|x86.Build.0 = Release|Any CPU
2462
EndGlobalSection
2563
GlobalSection(SolutionProperties) = preSolution
2664
HideSolutionNode = FALSE
2765
EndGlobalSection
66+
GlobalSection(NestedProjects) = preSolution
67+
{7FB99E3F-AC58-B8E3-DDC8-7641B56C22C3} = {FF13A09E-0E72-1904-124B-A4E979EF28D3}
68+
{363E1752-33E4-471A-9FD0-5C1C941EFB2B} = {7FB99E3F-AC58-B8E3-DDC8-7641B56C22C3}
69+
EndGlobalSection
2870
GlobalSection(ExtensibilityGlobals) = postSolution
2971
SolutionGuid = {D75BE430-E486-4A74-9063-D4A8A1C91261}
3072
EndGlobalSection
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.CommandLine;
2+
using OwlCore.Diagnostics;
3+
using WindowsAppCommunity.Sdk;
4+
5+
namespace WindowsAppCommunity.CommandLine.Common.AccentColor;
6+
7+
/// <summary>
8+
/// Wacsdk get accent color command.
9+
/// </summary>
10+
public abstract class GetAccentColorCommand : Command
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="GetAccentColorCommand"/> class.
14+
/// </summary>
15+
public GetAccentColorCommand(WacsdkCommandConfig config, string entityType, Option<string> repoOption, Option<string> idOption)
16+
: base("get", $"Gets the accent color for the {entityType}.")
17+
{
18+
AddOption(repoOption);
19+
AddOption(idOption);
20+
21+
this.SetHandler(InvokeAsync, repoOption, idOption);
22+
this.Config = config;
23+
}
24+
25+
protected WacsdkCommandConfig Config { get; init; }
26+
27+
public async Task InvokeAsync(string repo, string id)
28+
{
29+
var cancellationToken = Config.CancellationToken;
30+
cancellationToken.ThrowIfCancellationRequested();
31+
32+
Logger.LogInformation($"Getting entity");
33+
var entity = await GetEntityAsync(repo, id, cancellationToken);
34+
Logger.LogInformation($"Got {nameof(entity.Id)}: {entity.Id}");
35+
Logger.LogInformation($"{nameof(entity.AccentColor)}: {entity.AccentColor}");
36+
}
37+
38+
public abstract Task<IReadOnlyAccentColor> GetEntityAsync(string repoId, string entityId, CancellationToken cancellationToken);
39+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.CommandLine;
2+
using OwlCore.Diagnostics;
3+
using WindowsAppCommunity.Sdk;
4+
5+
namespace WindowsAppCommunity.CommandLine.Common.AccentColor;
6+
7+
/// <summary>
8+
/// Wacsdk set accent color command.
9+
/// </summary>
10+
public abstract class SetAccentColorCommand : Command
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="SetAccentColorCommand"/> class.
14+
/// </summary>
15+
public SetAccentColorCommand(WacsdkCommandConfig config, string entityType, Option<string> repoOption, Option<string> idOption, Option<string> valueOption)
16+
: base("set", $"Sets the accent color for the {entityType}.")
17+
{
18+
AddOption(repoOption);
19+
AddOption(idOption);
20+
AddOption(valueOption);
21+
22+
this.SetHandler(InvokeAsync, repoOption, idOption, valueOption);
23+
this.Config = config;
24+
}
25+
26+
protected WacsdkCommandConfig Config { get; init; }
27+
28+
public async Task InvokeAsync(string repo, string id, string value)
29+
{
30+
var cancellationToken = Config.CancellationToken;
31+
cancellationToken.ThrowIfCancellationRequested();
32+
33+
Logger.LogInformation($"Getting modifiable entity");
34+
var entity = await GetModifiableEntityAsync(repo, id, cancellationToken);
35+
Logger.LogInformation($"Got {nameof(entity.Id)}: {entity.Id}");
36+
37+
Logger.LogInformation($"Updating {nameof(entity.AccentColor)}: {value}");
38+
await entity.UpdateAccentColorAsync(value, cancellationToken);
39+
40+
await PublishAsync(entity, cancellationToken);
41+
}
42+
43+
public abstract Task<IModifiableAccentColor> GetModifiableEntityAsync(string repoId, string entityId, CancellationToken cancellationToken);
44+
45+
public abstract Task PublishAsync(IModifiableAccentColor entity, CancellationToken cancellationToken);
46+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.CommandLine;
2+
using OwlCore.Diagnostics;
3+
using WindowsAppCommunity.Sdk;
4+
5+
namespace WindowsAppCommunity.CommandLine.Common.Connections;
6+
7+
/// <summary>
8+
/// Wacsdk add connection command.
9+
/// </summary>
10+
public abstract class AddConnectionCommand : Command
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="AddConnectionCommand"/> class.
14+
/// </summary>
15+
public AddConnectionCommand(WacsdkCommandConfig config, string entityType, Option<string> repoOption, Option<string> idOption, Option<string> connectionIdOption, Option<string> connectionValueOption)
16+
: base("add", $"Adds a connection to the {entityType}.")
17+
{
18+
AddOption(repoOption);
19+
AddOption(idOption);
20+
AddOption(connectionIdOption);
21+
AddOption(connectionValueOption);
22+
23+
this.SetHandler(InvokeAsync, repoOption, idOption, connectionIdOption, connectionValueOption);
24+
this.Config = config;
25+
}
26+
27+
protected WacsdkCommandConfig Config { get; init; }
28+
29+
public async Task InvokeAsync(string repo, string id, string connectionId, string connectionValue)
30+
{
31+
var cancellationToken = Config.CancellationToken;
32+
cancellationToken.ThrowIfCancellationRequested();
33+
34+
Logger.LogInformation($"Getting modifiable entity");
35+
var entity = await GetModifiableEntityAsync(repo, id, cancellationToken);
36+
Logger.LogInformation($"Got {nameof(entity.Id)}: {entity.Id}");
37+
38+
var connection = new InMemoryConnection { Id = connectionId, Value = connectionValue };
39+
Logger.LogInformation($"Adding connection");
40+
Logger.LogInformation($"{nameof(connection.Id)}: {connection.Id}");
41+
Logger.LogInformation($"{nameof(connection.Value)}: {connection.Value}");
42+
await entity.AddConnectionAsync(connection, cancellationToken);
43+
44+
await PublishAsync(entity, cancellationToken);
45+
}
46+
47+
public abstract Task<IModifiableConnectionsCollection> GetModifiableEntityAsync(string repoId, string entityId, CancellationToken cancellationToken);
48+
49+
public abstract Task PublishAsync(IModifiableConnectionsCollection entity, CancellationToken cancellationToken);
50+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.CommandLine;
2+
using OwlCore.Diagnostics;
3+
using WindowsAppCommunity.Sdk;
4+
5+
namespace WindowsAppCommunity.CommandLine.Common.Connections;
6+
7+
/// <summary>
8+
/// Wacsdk get connections command.
9+
/// </summary>
10+
public abstract class GetConnectionsCommand : Command
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="GetConnectionsCommand"/> class.
14+
/// </summary>
15+
public GetConnectionsCommand(WacsdkCommandConfig config, string entityType, Option<string> repoOption, Option<string> idOption)
16+
: base("get", $"Gets the connections for the {entityType}.")
17+
{
18+
AddOption(repoOption);
19+
AddOption(idOption);
20+
21+
this.SetHandler(InvokeAsync, repoOption, idOption);
22+
this.Config = config;
23+
}
24+
25+
protected WacsdkCommandConfig Config { get; init; }
26+
27+
public async Task InvokeAsync(string repo, string id)
28+
{
29+
var cancellationToken = Config.CancellationToken;
30+
cancellationToken.ThrowIfCancellationRequested();
31+
32+
Logger.LogInformation($"Getting entity");
33+
var entity = await GetEntityAsync(repo, id, cancellationToken);
34+
Logger.LogInformation($"Got {nameof(entity.Id)}: {entity.Id}");
35+
36+
Logger.LogInformation($"Enumerating connections");
37+
await foreach (var connection in entity.GetConnectionsAsync(cancellationToken))
38+
{
39+
Logger.LogInformation($"Connection: {connection.Id}");
40+
}
41+
}
42+
43+
public abstract Task<IReadOnlyConnectionsCollection> GetEntityAsync(string repoId, string entityId, CancellationToken cancellationToken);
44+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.CommandLine;
2+
using OwlCore.Diagnostics;
3+
using WindowsAppCommunity.Sdk;
4+
5+
namespace WindowsAppCommunity.CommandLine.Common.Connections;
6+
7+
/// <summary>
8+
/// Wacsdk remove connection command.
9+
/// </summary>
10+
public abstract class RemoveConnectionCommand : Command
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="RemoveConnectionCommand"/> class.
14+
/// </summary>
15+
public RemoveConnectionCommand(WacsdkCommandConfig config, string entityType, Option<string> repoOption, Option<string> idOption, Option<string> connectionIdOption)
16+
: base("remove", $"Removes a connection from the {entityType}.")
17+
{
18+
AddOption(repoOption);
19+
AddOption(idOption);
20+
AddOption(connectionIdOption);
21+
22+
this.SetHandler(InvokeAsync, repoOption, idOption, connectionIdOption);
23+
this.Config = config;
24+
}
25+
26+
protected WacsdkCommandConfig Config { get; init; }
27+
28+
public async Task InvokeAsync(string repo, string id, string connectionId)
29+
{
30+
var cancellationToken = Config.CancellationToken;
31+
cancellationToken.ThrowIfCancellationRequested();
32+
33+
Logger.LogInformation($"Getting modifiable entity");
34+
var entity = await GetModifiableEntityAsync(repo, id, cancellationToken);
35+
Logger.LogInformation($"Got {nameof(entity.Id)}: {entity.Id}");
36+
37+
await foreach (var connection in entity.GetConnectionsAsync(cancellationToken))
38+
{
39+
if (connection.Id == connectionId)
40+
{
41+
await entity.RemoveConnectionAsync(connection, cancellationToken);
42+
Logger.LogInformation($"Removed connection: {connection.Id}");
43+
44+
await PublishAsync(entity, cancellationToken);
45+
return;
46+
}
47+
}
48+
49+
Logger.LogWarning($"Connection with ID {connectionId} not found.");
50+
}
51+
52+
public abstract Task<IModifiableConnectionsCollection> GetModifiableEntityAsync(string repoId, string entityId, CancellationToken cancellationToken);
53+
54+
public abstract Task PublishAsync(IModifiableConnectionsCollection entity, CancellationToken cancellationToken);
55+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.CommandLine;
2+
using OwlCore.Diagnostics;
3+
using WindowsAppCommunity.Sdk;
4+
5+
namespace WindowsAppCommunity.CommandLine.Common.Entity.Description;
6+
7+
/// <summary>
8+
/// Wacsdk get entity description command.
9+
/// </summary>
10+
public abstract class GetEntityDescriptionCommand : Command
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="GetEntityDescriptionCommand"/> class.
14+
/// </summary>
15+
public GetEntityDescriptionCommand(WacsdkCommandConfig config, string entityType, Option<string> repoOption, Option<string> idOption)
16+
: base("get", $"Gets the description for the {entityType}.")
17+
{
18+
AddOption(repoOption);
19+
AddOption(idOption);
20+
21+
this.SetHandler(InvokeAsync, repoOption, idOption);
22+
this.Config = config;
23+
}
24+
25+
protected WacsdkCommandConfig Config { get; init; }
26+
27+
public async Task InvokeAsync(string repo, string id)
28+
{
29+
var cancellationToken = Config.CancellationToken;
30+
cancellationToken.ThrowIfCancellationRequested();
31+
32+
Logger.LogInformation($"Getting entity");
33+
var entity = await GetEntityAsync(repo, id, cancellationToken);
34+
Logger.LogInformation($"Got {nameof(entity.Id)}: {entity.Id}");
35+
Logger.LogInformation($"{nameof(entity.Description)}: {entity.Description}");
36+
}
37+
38+
public abstract Task<IReadOnlyEntity> GetEntityAsync(string repoId, string entityId, CancellationToken cancellationToken);
39+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.CommandLine;
2+
using OwlCore.Diagnostics;
3+
using WindowsAppCommunity.Sdk;
4+
5+
namespace WindowsAppCommunity.CommandLine.Common.Entity.Description;
6+
7+
/// <summary>
8+
/// Wacsdk set entity description command.
9+
/// </summary>
10+
public abstract class SetEntityDescriptionCommand : Command
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="SetEntityDescriptionCommand"/> class.
14+
/// </summary>
15+
public SetEntityDescriptionCommand(WacsdkCommandConfig config, string entityType, Option<string> repoOption, Option<string> idOption, Option<string> valueOption)
16+
: base("set", $"Sets the description for the {entityType}.")
17+
{
18+
AddOption(repoOption);
19+
AddOption(idOption);
20+
AddOption(valueOption);
21+
22+
this.SetHandler(InvokeAsync, repoOption, idOption, valueOption);
23+
this.Config = config;
24+
}
25+
26+
protected WacsdkCommandConfig Config { get; init; }
27+
28+
public async Task InvokeAsync(string repo, string id, string value)
29+
{
30+
var cancellationToken = Config.CancellationToken;
31+
cancellationToken.ThrowIfCancellationRequested();
32+
33+
Logger.LogInformation($"Getting modifiable entity");
34+
var entity = await GetModifiableEntityAsync(repo, id, cancellationToken);
35+
Logger.LogInformation($"Got {nameof(entity.Id)}: {entity.Id}");
36+
37+
Logger.LogInformation($"Updating {nameof(entity.Description)}: {value}");
38+
await entity.UpdateDescriptionAsync(value, cancellationToken);
39+
40+
await PublishAsync(entity, cancellationToken);
41+
}
42+
43+
public abstract Task<IModifiableEntity> GetModifiableEntityAsync(string repoId, string entityId, CancellationToken cancellationToken);
44+
45+
public abstract Task PublishAsync(IModifiableEntity entity, CancellationToken cancellationToken);
46+
}

0 commit comments

Comments
 (0)