Ejemplo n.º 1
0
        private int List(Settings settings)
        {
            var examples = _finder.FindExamples();

            if (examples.Count == 0)
            {
                AnsiConsole.Markup("[yellow]No examples could be found.[/]");
                return(0);
            }

            AnsiConsole.WriteLine();

            var rows = new Grid().Collapse();

            rows.AddColumn();
            foreach (var group in examples.GroupBy(ex => ex.Group))
            {
                rows.AddRow(CreateTable(settings, group.Key, group));
                rows.AddEmptyRow();
            }

            AnsiConsole.Render(rows);

            AnsiConsole.MarkupLine("Type [blue]dotnet example --help[/] for help");

            return(0);
        }
Ejemplo n.º 2
0
        private int List()
        {
            var examples = _finder.FindExamples();

            if (examples.Count == 0)
            {
                AnsiConsole.Markup("[yellow]No examples could be found.[/]");
                return(0);
            }

            var grid = new Table {
                Border = TableBorder.Rounded
            };

            grid.AddColumn(new TableColumn("[grey]Name[/]")
            {
                NoWrap = true,
            });
            grid.AddColumn(new TableColumn("[grey]Path[/]")
            {
                NoWrap = true,
            });
            grid.AddColumn(new TableColumn("[grey]Description[/]"));

            foreach (var example in examples.OrderBy(e => e.Order))
            {
                var path = _environment.WorkingDirectory.GetRelativePath(example.Path);

                grid.AddRow(
                    $"[underline blue]{example.Name}[/]",
                    $"[grey]{path.FullPath}[/]",
                    !string.IsNullOrEmpty(example.Description)
                        ? $"{example.Description}"
                        : "[grey]N/A[/]");
            }

            AnsiConsole.WriteLine();
            AnsiConsole.MarkupLine("[u]Available examples:[/]");
            AnsiConsole.WriteLine();
            AnsiConsole.Render(grid);
            AnsiConsole.WriteLine();
            AnsiConsole.MarkupLine("Type [blue]dotnet example --help[/] for help");

            return(0);
        }
Ejemplo n.º 3
0
    public ProjectInformation?Select()
    {
        var examples = _finder.FindExamples();

        if (examples.Count == 0)
        {
            _console.Markup("[yellow]No examples could be found.[/]");
            return(null);
        }

        var prompt = new SelectionPrompt <string>();
        var groups = examples.GroupBy(ex => ex.Group);

        if (groups.Count() == 1)
        {
            prompt.AddChoices(examples.Select(x => x.Name));
        }
        else
        {
            var noGroupExamples = new List <string>();

            foreach (var group in groups)
            {
                if (string.IsNullOrEmpty(group.Key))
                {
                    noGroupExamples.AddRange(group.Select(x => x.Name));
                }
                else
                {
                    prompt.AddChoiceGroup(
                        group.Key,
                        group.Select(x => x.Name));
                }
            }

            if (noGroupExamples.Count > 0)
            {
                prompt.AddChoices(noGroupExamples);
            }
        }

        var example = AnsiConsole.Prompt(prompt
                                         .Title("[yellow]Choose example to run[/]")
                                         .MoreChoicesText("[grey](Move up and down to reveal more examples)[/]")
                                         .Mode(SelectionMode.Leaf));

        return(examples.FirstOrDefault(x => x.Name == example));
    }
Ejemplo n.º 4
0
    public void List()
    {
        var examples = _finder.FindExamples();

        if (examples.Count == 0)
        {
            _console.Markup("[yellow]No examples could be found.[/]");
            return;
        }

        _console.WriteLine();

        var rows = new Grid().Collapse();

        rows.AddColumn();
        foreach (var group in examples.GroupBy(ex => ex.Group))
        {
            rows.AddRow(CreateTable(group.Key, group));
            rows.AddEmptyRow();
        }

        _console.Write(rows);
        _console.MarkupLine("Type [blue]dotnet example --help[/] for help");
    }
Ejemplo n.º 5
0
    public async Task <int> RunAll(IRemainingArguments remaining)
    {
        var examples = _finder.FindExamples();

        foreach (var(_, first, _, example) in examples.Enumerate())
        {
            if (!first)
            {
                _console.WriteLine();
            }

            _console.Write(new Rule($"Example: [silver]{example.Name}[/]").LeftAligned().RuleStyle("grey"));

            var exitCode = await Run(example.Name, remaining).ConfigureAwait(false);

            if (exitCode != 0)
            {
                _console.MarkupLine($"[red]Error:[/] Example [u]{example.Name}[/] did not return a successful exit code.");
                return(exitCode);
            }
        }

        return(0);
    }
Ejemplo n.º 6
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));
        }
    }