mirror of
https://github.com/yaakov-h/Shamir.git
synced 2025-01-18 08:46:33 +00:00
Cleanup, implement first Steam command
This commit is contained in:
parent
1a3b150b27
commit
5d72217e61
7 changed files with 74 additions and 13 deletions
|
@ -22,7 +22,7 @@ namespace Shamir.Abstractions
|
||||||
|
|
||||||
public ValueTask<int> ExecuteAsync(IServiceProvider serviceProvider)
|
public ValueTask<int> ExecuteAsync(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
System.Console.Error.WriteLine(GetHelpText());
|
Console.Error.WriteLine(GetHelpText());
|
||||||
return ValueTask.FromResult(1); // TODO: const
|
return ValueTask.FromResult(1); // TODO: const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace Shamir.Abstractions
|
||||||
var helpText = HelpText.AutoBuild(result);
|
var helpText = HelpText.AutoBuild(result);
|
||||||
helpText.Heading = string.Empty;
|
helpText.Heading = string.Empty;
|
||||||
helpText.Copyright = string.Empty;
|
helpText.Copyright = string.Empty;
|
||||||
System.Console.Error.WriteLine(helpText);
|
Console.Error.WriteLine(helpText);
|
||||||
return ValueTask.FromResult(1);
|
return ValueTask.FromResult(1);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace Shamir.Commands.Radio
|
||||||
|
|
||||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||||
{
|
{
|
||||||
System.Console.WriteLine($"{options.Callsign}: No such callsign found.");
|
Console.WriteLine($"{options.Callsign}: No such callsign found.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,32 +46,32 @@ namespace Shamir.Commands.Radio
|
||||||
|
|
||||||
if (json.RootElement.TryGetProperty("callsign", out var callsign))
|
if (json.RootElement.TryGetProperty("callsign", out var callsign))
|
||||||
{
|
{
|
||||||
System.Console.Write("Callsign : ");
|
Console.Write("Callsign : ");
|
||||||
System.Console.WriteLine(callsign.GetString());
|
Console.WriteLine(callsign.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.RootElement.TryGetProperty("name", out var name))
|
if (json.RootElement.TryGetProperty("name", out var name))
|
||||||
{
|
{
|
||||||
System.Console.Write("Name : ");
|
Console.Write("Name : ");
|
||||||
System.Console.WriteLine(name.GetString());
|
Console.WriteLine(name.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.RootElement.TryGetProperty("suburb", out var suburb))
|
if (json.RootElement.TryGetProperty("suburb", out var suburb))
|
||||||
{
|
{
|
||||||
System.Console.Write("Suburb : ");
|
Console.Write("Suburb : ");
|
||||||
System.Console.WriteLine(suburb.GetString());
|
Console.WriteLine(suburb.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.RootElement.TryGetProperty("state", out var state))
|
if (json.RootElement.TryGetProperty("state", out var state))
|
||||||
{
|
{
|
||||||
System.Console.Write("State : ");
|
Console.Write("State : ");
|
||||||
System.Console.WriteLine(state.GetString());
|
Console.WriteLine(state.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.RootElement.TryGetProperty("link", out var link))
|
if (json.RootElement.TryGetProperty("link", out var link))
|
||||||
{
|
{
|
||||||
System.Console.Write("Link : ");
|
Console.Write("Link : ");
|
||||||
System.Console.WriteLine(link.GetString());
|
Console.WriteLine(link.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
33
src/commands/steam/DescribeGidCommand.cs
Normal file
33
src/commands/steam/DescribeGidCommand.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using CommandLine;
|
||||||
|
using Shamir.Abstractions;
|
||||||
|
using SteamKit2;
|
||||||
|
|
||||||
|
namespace Shamir.Commands.Radio
|
||||||
|
{
|
||||||
|
public class DescribeGidOptions
|
||||||
|
{
|
||||||
|
[Value(0, MetaName = "gid", Required = true, HelpText = "Global ID to describe.")]
|
||||||
|
public ulong Gid { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class DescribeGidCommand : ParsedArgumentsCommand<DescribeGidOptions>
|
||||||
|
{
|
||||||
|
public override string Name => "gid";
|
||||||
|
|
||||||
|
public override string Description => "Explain a gid_t (Global ID)";
|
||||||
|
|
||||||
|
public override ValueTask<int> ExecuteAsync(IServiceProvider serviceProvider, DescribeGidOptions options)
|
||||||
|
{
|
||||||
|
var gid = new GlobalID(options.Gid);
|
||||||
|
|
||||||
|
Console.WriteLine($"Box ID : {gid.BoxID}");
|
||||||
|
Console.WriteLine($"Process ID : {gid.ProcessID}");
|
||||||
|
Console.WriteLine($"Process Start Time : {gid.StartTime}");
|
||||||
|
Console.WriteLine($"Sequence : {gid.SequentialCount}");
|
||||||
|
|
||||||
|
return ValueTask.FromResult(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
src/commands/steam/ServiceCollectionExtensions.cs
Normal file
22
src/commands/steam/ServiceCollectionExtensions.cs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Shamir.Abstractions;
|
||||||
|
|
||||||
|
namespace Shamir.Commands.Radio
|
||||||
|
{
|
||||||
|
public static class ServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddSteamCommandTree(this IServiceCollection collection)
|
||||||
|
{
|
||||||
|
collection.AddTransient<ICommandTree>(sp => new DefaultCommandTree(
|
||||||
|
"steam",
|
||||||
|
"Steam Network utilities",
|
||||||
|
ImmutableArray<ICommandTree>.Empty,
|
||||||
|
ImmutableArray.Create<ICommand>(
|
||||||
|
new DescribeGidCommand()
|
||||||
|
)));
|
||||||
|
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,10 +4,15 @@
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<RootNamespace>Shamir.Commands.Steam</RootNamespace>
|
<RootNamespace>Shamir.Commands.Steam</RootNamespace>
|
||||||
<AssemblyName>Shamir.Commands.Steam</AssemblyName>
|
<AssemblyName>Shamir.Commands.Steam</AssemblyName>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\abstractions\abstractions.csproj" />
|
<ProjectReference Include="..\..\abstractions\abstractions.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="SteamKit2" Version="2.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Shamir.Console
|
||||||
}))
|
}))
|
||||||
.AddAzureCommandTree()
|
.AddAzureCommandTree()
|
||||||
.AddRadioCommandTree()
|
.AddRadioCommandTree()
|
||||||
|
.AddSteamCommandTree()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
using var scope = serviceProvider.CreateScope();
|
using var scope = serviceProvider.CreateScope();
|
||||||
|
|
Loading…
Reference in a new issue