Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badge trading #231

Open
wants to merge 21 commits into
base: badge-trading
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TPP.ArgsParsing/TypeParsers/AnyOrderParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public async Task<ArgsParseResult<AnyOrder>> Parse(
2 => typeof(AnyOrder<,>),
3 => typeof(AnyOrder<,,>),
4 => typeof(AnyOrder<,,,>),
5 => typeof(AnyOrder<,,,,>),
6 => typeof(AnyOrder<,,,,,>),
var num => throw new InvalidOperationException(
$"An implementation of {typeof(AnyOrder)} for {num} generic arguments " +
"needs to be implemented and wired up where this exception is thrown. " +
Expand Down
37 changes: 37 additions & 0 deletions TPP.ArgsParsing/TypeParsers/BadgeSourceParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using TPP.Model;

namespace TPP.ArgsParsing.TypeParsers
{
public class BadgeSourceParser : IArgumentParser<Badge.BadgeSource>
{
public Task<ArgsParseResult<Badge.BadgeSource>> Parse(IImmutableList<string> args, Type[] genericTypes)
{
string source = args[0];
ArgsParseResult<Badge.BadgeSource> result;
Badge.BadgeSource? parsedSource = null;
try
{
parsedSource = (Badge.BadgeSource)Enum.Parse(typeof(Badge.BadgeSource), source, ignoreCase: true);
}
catch (ArgumentException)
{
switch (args[1].ToLower())
{
case "run":
case "caught":
parsedSource = Badge.BadgeSource.RunCaught;
break;
}
}
if (parsedSource != null)
result = ArgsParseResult<Badge.BadgeSource>.Success(parsedSource.Value, args.Skip(1).ToImmutableList());
else
result = ArgsParseResult<Badge.BadgeSource>.Failure($"Did not find a source named '{args[0]}'");
return Task.FromResult(result);
}
}
}
Loading