public DefaultCommand()
        {
            var fileSystem  = new FileSystem();
            var environment = new Environment();
            var globber     = new Globber(fileSystem, environment);

            _environment = environment;
            _finder      = new ExampleFinder(fileSystem, environment, globber);
            _lister      = new SourceLister(fileSystem, globber);
        }
Beispiel #2
0
 public ExampleLister(IAnsiConsole console, ExampleFinder finder)
 {
     _console = console ?? throw new ArgumentNullException(nameof(console));
     _finder  = finder ?? throw new ArgumentNullException(nameof(finder));
 }
Beispiel #3
0
    public override async Task <int> ExecuteAsync(CommandContext context, Settings settings)
    {
        if (settings.All)
        {
            var finder = new ExampleFinder(_fileSystem, _environment, _globber, settings.Skip);
            var runner = new ExampleRunner(_console, finder);
            return(await runner.RunAll(context.Remaining).ConfigureAwait(false));
        }
        else if (settings.Select)
        {
            var finder   = new ExampleFinder(_fileSystem, _environment, _globber, settings.Skip);
            var selector = new ExampleSelector(_console, finder);

            var example = selector.Select();
            if (example == null)
            {
                return(-1);
            }

            if (settings.Source)
            {
                var sourceLister = new ExampleSourceLister(_fileSystem, _globber);
                if (!sourceLister.List(example))
                {
                    return(-1);
                }

                return(0);
            }
            else
            {
                var runner = new ExampleRunner(_console, finder);
                return(await runner.Run(example.Name, context.Remaining).ConfigureAwait(false));
            }
        }
        else if (settings.List || string.IsNullOrWhiteSpace(settings.Name))
        {
            var finder = new ExampleFinder(_fileSystem, _environment, _globber, settings.Skip);

            // Only one example?
            var examples = finder.FindExamples();
            if (examples.Count == 1)
            {
                // Execute it
                var runner = new ExampleRunner(_console, finder);
                return(await runner.Run(examples[0].Name, context.Remaining).ConfigureAwait(false));
            }

            var lister = new ExampleLister(_console, finder);
            lister.List();
            return(0);
        }
        else if (settings.Source)
        {
            var finder  = new ExampleFinder(_fileSystem, _environment, _globber, settings.Skip);
            var example = finder.FindExample(settings.Name);
            if (example == null)
            {
                return(-1);
            }

            var lister = new ExampleSourceLister(_fileSystem, _globber);
            if (!lister.List(example))
            {
                return(-1);
            }

            return(0);
        }
        else
        {
            var finder = new ExampleFinder(_fileSystem, _environment, _globber, settings.Skip);
            var runner = new ExampleRunner(_console, finder);
            return(await runner.Run(settings.Name, context.Remaining).ConfigureAwait(false));
        }
    }