35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using System;
|
|
using static System.Console;
|
|
|
|
namespace ProtosXdigitalDemo
|
|
{
|
|
internal class CommandLineParser
|
|
{
|
|
public string? RecipeName { get; }
|
|
public int TimesToRepeat { get; }
|
|
|
|
private CommandLineParser(string? recipeName, int timesToRepeat)
|
|
{
|
|
RecipeName = recipeName;
|
|
TimesToRepeat = timesToRepeat;
|
|
}
|
|
|
|
public static CommandLineParser Parse(string[] args)
|
|
{
|
|
return args.Length switch
|
|
{
|
|
0 => new CommandLineParser(null, 0),
|
|
1 => new CommandLineParser(args[0], 0),
|
|
2 => new CommandLineParser(args[0], Convert.ToInt32(args[1])),
|
|
_ => ExitOnTooManyArgs()
|
|
};
|
|
}
|
|
|
|
private static CommandLineParser ExitOnTooManyArgs()
|
|
{
|
|
WriteLine("Too many command-line arguments; exiting.");
|
|
Environment.Exit(Data.MachineState.failureCode[2]);
|
|
throw new OperationCanceledException();
|
|
}
|
|
}
|
|
} |