wp-cli / scaffold-package-command

Scaffolds WP-CLI commands with functional tests, full README.md, and more.
MIT License
69 stars 20 forks source link

Convert '~/' when supplied in `$package_dir` #127

Closed danielbachhuber closed 7 years ago

danielbachhuber commented 7 years ago

Fixes #119

danielbachhuber commented 7 years ago

@schlessera I'm not sure realpath() is the way to go because:

The running script must have executable permissions on all directories in the hierarchy, otherwise realpath() will return FALSE.

Thoughts?

schlessera commented 7 years ago

Maybe use our own helper functions, something like this: https://3v4l.org/9Ga8c

schlessera commented 7 years ago

Drush uses this: https://github.com/webmozart/path-util

gitlost commented 7 years ago

As it's very Unixy could just do something like

if ( '~/' === substr( $package_dir, 0, 2 ) && ( $home = getenv( 'HOME' ) ) ) {
    $package_dir = $home . substr( $package_dir, 1 );
}
schlessera commented 7 years ago

@gitlost Yes, I suggested a more robust version of that here: https://3v4l.org/9Ga8c

danielbachhuber commented 7 years ago

@schlessera @gitlost Updated. I went with the simpler approach to begin with.

schlessera commented 7 years ago

I'm not sure why you'd want to solve this partially only. It is highly probable someone will want to use a relative path with this as well, and just create a new bug report at that point.

Additionally, having ~ work, and not . or .. makes it even worse in that it is inconsistent as well.

gitlost commented 7 years ago

I don't see how a relative path or . or .. won't just work - just tried --dir=~/../blah and it worked...

schlessera commented 7 years ago

Oh, okay, I just assumed it would create issues as well. All good then.