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

Laravel Prompts in Starter Kit not interactive #62

Open
marcorieser opened this issue Sep 18, 2023 · 3 comments
Open

Laravel Prompts in Starter Kit not interactive #62

marcorieser opened this issue Sep 18, 2023 · 3 comments
Labels

Comments

@marcorieser
Copy link

Rob and I migrated the Post Install Script of Peak over to Laravel Prompts (studio1902/statamic-peak#348).

So far so good and the prompts work as expected when installing Peak into an existing Statamic installation by running php please starter-kit:install studio1902/statamic-peak --local.

However, when running statamic new my-project studio1902/statamic-peak --local the prompts do not show up asking for input but apply the default value. I can reproduce the same behaviour when running php please starter-kit:install studio1902/statamic-peak --local --no-interaction (notice the --no-interaction).

I dumped the $options before they get passed into the starter kit installation but the --no-interaction is missing.

cli/src/NewCommand.php

Lines 550 to 552 in d320fbb

$statusCode = (new Please($this->output))
->cwd($this->absolutePath)
->run('starter-kit:install', $this->starterKit, ...$options);

Array
(
    [0] => --cli-install
    [1] => --clear-site
    [2] => --local
)
@marcorieser
Copy link
Author

marcorieser commented Nov 1, 2023

Invested some time yesterday and found out that ['--no-interaction' => true] here seems to cause the issue.

if ($cleared = $this->shouldClear()) {
    $this->call('statamic:site:clear', ['--no-interaction' => true]);
}

As soon as I remove that call or set it to interactive, the prompts in the starter kit post install hook ask for input rather than applying the default (--no-interaction).

I have no clue why this is happening. The method seems to restore the interactivity somehow because dumping $this->input shows interactive => true. Maybe it's possible to run the clear command as subprocess to prevent side effects (whatever that means, just thinking out loud).

Adding a prompt (eg. text('Whatever');) after the clear call above is interactive. Meaning it's somehow only affecting the starter kit post install hook.

@marcorieser
Copy link
Author

Not sure if this issue belongs to the cli repo anymore since the "issue code" is inside the cms repo.

@marcorieser
Copy link
Author

marcorieser commented Nov 1, 2023

For now: We now reapply the interactivity state for prompts in the post install hook:

    protected function applyInteractivity($console): void
    {
        $this->interactive = !$console->option('no-interaction');


        /**
         * Interactivity should be inherited but seems like there is a bug in Prompts where it stays
         * without interaction when a command was run before with `--no-interaction` flag.
         */
        Prompt::interactive($this->interactive);
    }

https://github.com/studio1902/statamic-peak/blob/af618776e6b4b9dd22dce2a595141ce065a8d4a9/StarterKitPostInstall.php#L34-L43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants