Skip to content

Add one more potential path for templates#10

Closed
danielbachhuber wants to merge 1 commit intomasterfrom
9-one-more-path
Closed

Add one more potential path for templates#10
danielbachhuber wants to merge 1 commit intomasterfrom
9-one-more-path

Conversation

@danielbachhuber
Copy link
Member

@danielbachhuber danielbachhuber added this to the 1.0.2 milestone Apr 24, 2017
@danielbachhuber danielbachhuber added bug command:scaffold Related to 'scaffold' command labels Apr 24, 2017
@danielbachhuber
Copy link
Member Author

@schlessera To test:

git clone git@github.com:wp-cli/extension-command.git
cd extension-command
composer install --no-dev
composer require wp-cli/wp-cli:dev-master
export WP_CLI_BIN_DIR=$(pwd)/vendor/bin

I'd have to say this type of bug is quite annoying though. Definitely open to ideas on how we can improve.

@schlessera
Copy link
Member

I don't think that's a good approach to fix this bug.

The bug happens because you use the framework rootfolder to locate a command subfolder. As the command has been split out, it can move around independently of the framework.

So, I would recommend to locate the command subfolder based on the command rootfolder (or a known subfolder of the command), instead of the independent framework rootfolder.

Something like:

$template_path = dirname( __DIR__ ) . '/templates/' . $template;

@danielbachhuber
Copy link
Member Author

The bug happens because you use the framework rootfolder to locate a command subfolder. As the command has been split out, it can move around independently of the framework.

It's still dependent on WP_CLI_ROOT, though, to produce the proper path in a Phar.

So, I would recommend to locate the command subfolder based on the command rootfolder (or a known subfolder of the command), instead of the independent framework rootfolder.

This doesn't work inside the Phar.

@danielbachhuber
Copy link
Member Author

Related wp-cli/wp-cli#3987

@schlessera
Copy link
Member

schlessera commented Apr 27, 2017

I ran some tests, and I found a way to get the command path from within a phar. The basic code is this:

$command_root = dirname( str_replace( 'phar://' . getcwd() . '/', 'phar://', __DIR__ ) );
$template_path = $command_root . '/templates/' . $template;

This basically uses the __DIR__ constant (as reference to the command location) and removes the current working dir from it to reduce it to the phar portion.

What do you think? Is this something we can use?

schlessera added a commit that referenced this pull request Apr 28, 2017
Instead of relating the `/templates/` path to the (relatively) shifting WP-CLI framework, relate it to the command's root folder instead.

See #10
@danielbachhuber danielbachhuber removed this from the 1.0.2 milestone Apr 28, 2017
@danielbachhuber
Copy link
Member Author

Closing in favor of #12

@danielbachhuber danielbachhuber deleted the 9-one-more-path branch April 28, 2017 18:08
danielbachhuber pushed a commit that referenced this pull request Nov 18, 2022
Instead of relating the `/templates/` path to the (relatively) shifting WP-CLI framework, relate it to the command's root folder instead.

See #10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:scaffold Related to 'scaffold' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants