private int ViewSource(string name)
        {
            var example = _finder.FindExample(name);

            if (example == null)
            {
                return(-1);
            }

            _lister.List(example);

            return(0);
        }
示例#2
0
    public async Task <int> Run(string name, IRemainingArguments remaining)
    {
        var example = _finder.FindExample(name);

        if (example == null)
        {
            return(-1);
        }

        if (!await Build(example).ConfigureAwait(false))
        {
            return(-1);
        }

        var arguments = "run";

        if (remaining.Raw.Count > 0)
        {
            arguments += $"--no-build --no-restore -- {string.Join(" ", remaining.Raw)}";
        }

        // Run the example using "dotnet run"
        var info = new ProcessStartInfo("dotnet")
        {
            Arguments        = arguments,
            WorkingDirectory = example.GetWorkingDirectory().FullPath,
        };

        var process = Process.Start(info);

        if (process == null)
        {
            throw new InvalidOperationException("An error occured when starting the 'dotnet' process");
        }

        process.WaitForExit();
        return(process.ExitCode);
    }
示例#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));
        }
    }