Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: New Help as One for All #98

Closed
MuzafferDede opened this issue Apr 18, 2020 · 6 comments
Closed

Suggestion: New Help as One for All #98

MuzafferDede opened this issue Apr 18, 2020 · 6 comments

Comments

@MuzafferDede
Copy link

MuzafferDede commented Apr 18, 2020

Updated!

Hi, I would like to contribute by PR but not fully in control with the code structure at the moment, So I thought i could still make some suggestions.

The help function we talk on the live streaming, I think that could be something like this:

I believe we can convert DisplayHelpScreen class to handle lambo's and preset's help dynamically just passing the parameters to display.

DisplayHelpScreen class can accept usages, commands,options and flags each as array with description if needed and display them on condition if received.

Take a look at the concept code:

namespace App\Actions;

use App\Options;

class DisplayHelpScreen
{
    use LamboAction;

    protected $indent = 30;
    public $content = [];

    public function __construct($bindings = [])
    {
        foreach ($bindings as $key => $value) {
            $this->content[$key] = $value;
        }

        $this->display();
    }

    public function display()
    {
        foreach ($this->content as $key => $values) {
            $this->line("\n<comment>{$key}:</comment>");

            $values = is_array($values) ? $values : str_split($values);

            foreach ($values as $command => $description) {
                 $spaces = $this->makeSpaces(strlen($command));
                 $this->line("  <info>{$command || ''}</info>{$spaces}{$description}");
            }
        }
    }

    private function createCliStringForOption($option)
    {
        if (isset($option['short'])) {
            $flag = '-' . $option['short'] . ', --' . $option['long'];
        } else {
            $flag = '    --' . $option['long'];
        }

        if (isset($option['param_description'])) {
            $flag .= '=' . $option['param_description'];
        }

        $spaces = $this->makeSpaces(strlen($flag));
        $description = $option['cli_description'];

        return "  <info>{$flag}</info>{$spaces}{$description}";
    }

    public function makeSpaces($count)
    {
        return str_repeat(" ", $this->indent - $count);
    }
}


class Telescope
{
    public $usages = [
        '--preset=[preset]',
        '--preset=[preset]:[command]',
        '--preset=[preset]:[command]|[option]',
        '--preset=[preset]:[command]|[option]--[flag]',
    ];

    public $commands = [
        '[command1]' => '[description]',
        '[command2]' => '[description]',
    ];

    public $options = [
        '[option1]' => '[description]',
        '[option2]' => '[description]',
    ];

    public $flags = [
        '[flag1]' => '[description]',
        '[flag2]' => '[description]',
    ];

    public function help()
    {
        new DisplayHelpScreen([
            'usages'  => $this->usages,
            'commands'=> $this->commands,
            'options' => $this->options,
            'flags'   => $this->flags
        ]);
    }
}

(new Telescope())->help();

and lambo could use same way as any other presets. So this way, we could have a help template that displays different information for any use case. Passing the parameters could be done in a better way.

I didn't describe it too detailed because i think the idea is clear. It's a concept and i believe there is a lot of room to improve.
Thx

@mattstauffer
Copy link
Member

Imagine this:

  1. Rename help-screen to help
  2. Allow for passing a parameter to help, with one of these options:
  • ./lambo help edit-config (command)
  • ./lambo help editor (parameter)
  • ./lambo help nova (preset)

@m50
Copy link

m50 commented May 1, 2020

For calling the help:

if ($this->wantHelps) {
            $this->wantHelps = false;

            $helpCommand = $this->get('help');
            $helpCommand->setCommand($command);

            return $helpCommand;
        }

Looks like it pulls up the help command, still looking for unregistering help.

@m50
Copy link

m50 commented May 1, 2020

Help command is built in:

    /**
     * Gets the default commands that should always be available.
     *
     * @return Command[] An array of default Command instances
     */
    protected function getDefaultCommands()
    {
        return [new HelpCommand(), new ListCommand()];
    }

Line 984 symfony/console/Application.php.

Going to need to override the application and override that to replace the help command.

@jonsugar
Copy link
Collaborator

Labeled as in progress and assigned as work on this has started in the mes/presets branch.

@mattstauffer
Copy link
Member

Good news, it can be fixed by adding the Symfony help command to the "remove" block in config/commands

@jonsugar jonsugar closed this as completed Sep 7, 2020
@jonsugar jonsugar modified the milestone: Beta 2 Sep 7, 2020
@jonsugar
Copy link
Collaborator

jonsugar commented Sep 7, 2020

Done. Scheduled for release in Beta 2

@jonsugar jonsugar reopened this Sep 7, 2020
Lambo general development automation moved this from Done to In progress Sep 7, 2020
@jonsugar jonsugar closed this as completed Sep 7, 2020
Lambo general development automation moved this from In progress to Done Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

4 participants