Skip to content

mchechulnikov/photosphere-console

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Photosphere.Console

Set of command line utilities.

Status

Windows build Status NuGet license

Install via NuGet

PM> Install-Package Photosphere.Console

Interface

interface ICommandLineArgumentsParser<T> : IConsoleService where T : ICommandLineArguments
interface ICommandLineActionSelector<T> : IConsoleService where T : ICommandLineArguments

Example

// 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);
  }
}

About

Set of command line utility classes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages