Set of command line utilities.
PM> Install-Package Photosphere.Console
interface ICommandLineArgumentsParser<T> : IConsoleService where T : ICommandLineArguments
interface ICommandLineActionSelector<T> : IConsoleService where T : ICommandLineArguments
// if you use dependency injection, you can register services by common interface
registrator.Register<IConsoleService>();
class FooArguments : ICommandLineArguments
{
[ConsoleOption(Option = "f", BoundedActionType = typeof(CompileAction))]
public IReadOnlyList<string> FilePathes { get; set; }
[ConsoleOption(Option = "h", BoundedActionType = typeof(ShowHelpAction))]
public bool ShowHelp { get; set; }
}
class DoSomethingAction : ICommandLineAction<ICommandLineArguments>
{
public void Action(ICompilerArguments arguments)
{
Console.WriteLine("Do something!");
}
}
class ShowHelpAction : ICommandLineAction<ICompilerArguments>
{
public void Action(ICompilerArguments arguments)
{
Console.WriteLine("It's a help!");
}
}
class FooProgram
{
private readonly ICommandLineArgumentsParser<FooArguments> _commandLineArgumentsParser;
private readonly ICommandLineActionSelector<FooArguments> _commandLineActionSelector;
public FooProgram(
ICommandLineArgumentsParser<FooArguments> commandLineArgumentsParser,
ICommandLineActionSelector<FooArguments> commandLineActionSelector)
{
_commandLineArgumentsParser = commandLineArgumentsParser;
_commandLineActionSelector = commandLineActionSelector;
}
public void Start(IEnumerable<string> args)
{
var arguments = _commandLineArgumentsParser.Parse(args);
var action = _commandLineActionSelector.Select(arguments);
action(arguments);
}
}