getkirby / cli

Kirby Command Line Interface
MIT License
51 stars 5 forks source link

Check vendor folder when using kirby-cms-path: false #11

Open iskrisis opened 1 year ago

iskrisis commented 1 year ago

When using composer.json

"extra": {
   "kirby-cms-path": false,
}

the cli fails. I am not sure if "kirby-cms-path" sets the path or you can just use false so it's moved to vendor.

Using kirby.cli.json doesn't seem to help but that is pointing to vendor autoloader so it should not matter where kirby is?

bastianallgeier commented 1 year ago

Could you check if the version on develop fixes this problem for you? Make sure to run the CLI in the same root as your index.php

RobertCordes commented 1 year ago

For me this doesn’t work, even with the dev version (dev-main 9182f92). I have also tried using the kirby.cli.json but with no luck.

iamwebrocker commented 1 year ago

perhaps related… I have

Solved, see update below [1]

"extra": {
    "kirby-cms-path": "htdocs/kirby"
  }

in the composer.json.

and this directory structure:

<myabspath>
  composer.json
  -- htdocs
    .htaccess
    index.php
    -- kirby
    -- site
    ...

If I run the Kirby Cli in the directory where the composer.json is, it works - showing the possible commands. Now when I run kirby clear:cache for example, The Kirby installation could not be found is returned.

If I change into the "htdocs" directory (where the index.php and .htaccess etc "live"), and run the cli there, I get

PHP Warning:  require_once(/<myabspath>/htdocs/kirby/vendor/autoload.php): Failed to open stream: No such file or directory in /.config/composer/vendor/getkirby/cli/bin/kirby on line 17

Warning: require_once(/<myabspath>/htdocs/kirby/vendor/autoload.php): Failed to open stream: No such file or directory in /.config/composer/vendor/getkirby/cli/bin/kirby on line 17
PHP Fatal error:  Uncaught Error: Failed opening required '/<myabspath>/htdocs/kirby/vendor/autoload.php' (include_path='.:/usr/share/php:..') in /.config/composer/vendor/getkirby/cli/bin/kirby:17
Stack trace:
#0 /.config/composer/vendor/bin/kirby(120): include()
#1 {main}
  thrown in /.config/composer/vendor/getkirby/cli/bin/kirby on line 17

Fatal error: Uncaught Error: Failed opening required '/<myabspath>/htdocs/kirby/vendor/autoload.php' (include_path='.:/usr/share/php:..') in /.config/composer/vendor/getkirby/cli/bin/kirby:17
Stack trace:
#0 /.config/composer/vendor/bin/kirby(120): include()
#1 {main}
  thrown in /.config/composer/vendor/getkirby/cli/bin/kirby on line 17

I added a kirby.cli.json parallel to the composer.json, with

{
    "roots": {
        "index": "./htdocs",
    }
}

And then this error happens

PHP Fatal error:  Uncaught TypeError: Kirby\CLI\CLI::createOptions(): Return value must be of type array, null returned in /.config/composer/vendor/getkirby/cli/src/CLI/CLI.php:279
Stack trace:
#0 /.config/composer/vendor/getkirby/cli/src/CLI/CLI.php(43): Kirby\CLI\CLI->createOptions()
#1 /.config/composer/vendor/getkirby/cli/src/CLI/CLI.php(101): Kirby\CLI\CLI->__construct()
#2 /.config/composer/vendor/getkirby/cli/bin/kirby(23): Kirby\CLI\CLI::command()
#3 /.config/composer/vendor/bin/kirby(120): include('/.config/compos...')
#4 {main}
  thrown in /.config/composer/vendor/getkirby/cli/src/CLI/CLI.php on line 279

Fatal error: Uncaught TypeError: Kirby\CLI\CLI::createOptions(): Return value must be of type array, null returned in /.config/composer/vendor/getkirby/cli/src/CLI/CLI.php:279
Stack trace:
#0 /.config/composer/vendor/getkirby/cli/src/CLI/CLI.php(43): Kirby\CLI\CLI->createOptions()
#1 /.config/composer/vendor/getkirby/cli/src/CLI/CLI.php(101): Kirby\CLI\CLI->__construct()
#2 /.config/composer/vendor/getkirby/cli/bin/kirby(23): Kirby\CLI\CLI::command()
#3 /.config/composer/vendor/bin/kirby(120): include('/.config/compos...')
#4 {main}
  thrown in /.config/composer/vendor/getkirby/cli/src/CLI/CLI.php on line 279

if I run the cli from the root directory. changing into htdocs, the same require_once error as above happens.

I have a second installation where the composer.json, .htaccess, index.php and the kirby directory all are on the same level -- there the cli works fine.

Thanks for the cool new version, aside from the cli hickup described here, it was a very smooth update.

[1] Update: I reconsidered my structure. Why am I having the kirby directory inside my public (htdocs)? I guess this is from some legacy times… anyway I moved the kirby directory one level higher

<myabspath>
  composer.json
  -- kirby
  -- htdocs
    .htaccess
    index.php
    -- site
    ...

and modified the index.php inside htdocs as explained in the docs (https://getkirby.com/docs/cookbook/setup/composer#installing-kirby-to-a-custom-directory), changed the composer.json back to

...
"extra": {
    "kirby-cms-path": "kirby"
  }

ran composer update and now the cli works when called from inside my htdocs dir.

jensscherbl commented 3 months ago

Had the same issue. With a slightly customized setup and a public docroot inside the main project root, the cli tool only works from within the public docroot, not from the project root.