ConvertCommand.cs 1.0 KB

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Linq;
  3. using ArcToolkitCLI.Commands.Converters;
  4. using CommandLine;
  5. namespace ArcToolkitCLI.Commands
  6. {
  7. [Verb("convert", HelpText = "Convert between common data types")]
  8. public class ConvertCommand : ICommand
  9. {
  10. public int Run()
  11. {
  12. var commandTypes = typeof(ConvertCommand).Assembly.GetTypes()
  13. .Where(t => !t.IsInterface && !t.IsAbstract && t != typeof(BaseConverter) &&
  14. typeof(BaseConverter).IsAssignableFrom(t))
  15. .ToArray();
  16. return new Parser(with =>
  17. {
  18. with.IgnoreUnknownArguments = true;
  19. with.HelpWriter = Parser.Default.Settings.HelpWriter;
  20. }).ParseArguments(Environment.GetCommandLineArgs().Skip(2), commandTypes)
  21. .MapResult((object t) => ((BaseConverter)t).Run(), errs => 1);
  22. }
  23. }
  24. }