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

Clarify help text and error messages for invalid <dir> values #114

Merged
merged 3 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions features/scaffold-package-github.feature
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
Feature: Scaffold GitHub configuration for an existing package

Scenario: Fails when invalid package directory provided
Scenario: Fails when invalid directory provided
Given an empty directory

When I run `wp package path`
Then save STDOUT as {PACKAGE_PATH}
When I try `wp scaffold package-github bar`
Then the bar directory should not exist
And STDERR should be:
"""
Error: Directory does not exist.
"""

Scenario: Fails when invalid package provided
Given an empty directory
And a baz/empty file:
"""
"""

When I try `wp scaffold package-github {PACKAGE_PATH}/local/wp-cli/default-github`
Then STDERR should be:
When I try `wp scaffold package-github baz`
Then the baz directory should exist
But the baz/.github directory should not exist
And STDERR should be:
"""
Error: Invalid package directory. composer.json file must be present.
"""
Expand Down
24 changes: 24 additions & 0 deletions features/scaffold-package-readme.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
Feature: Scaffold a README.md file for an existing package

Scenario: Fails when invalid directory provided
Given an empty directory

When I try `wp scaffold package-readme bar`
Then the bar directory should not exist
And STDERR should be:
"""
Error: Directory does not exist.
"""

Scenario: Fails when invalid package provided
Given an empty directory
And a baz/empty file:
"""
"""

When I try `wp scaffold package-readme baz`
Then the baz directory should exist
But the baz/README.md file should not exist
And STDERR should be:
"""
Error: Invalid package directory. composer.json file must be present.
"""

Scenario: Scaffold a README.md based on the defaults
Given an empty directory

Expand Down
24 changes: 24 additions & 0 deletions features/scaffold-package-tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ Feature: Scaffold the test suite for an existing package
}
"""

Scenario: Fails when invalid directory provided
Given an empty directory

When I try `wp scaffold package-tests bar`
Then the bar directory should not exist
And STDERR should be:
"""
Error: Directory does not exist.
"""

Scenario: Fails when invalid package provided
Given an empty directory
And a baz/empty file:
"""
"""

When I try `wp scaffold package-tests baz`
Then the baz directory should exist
But the baz/features directory should not exist
And STDERR should be:
"""
Error: Invalid package directory. composer.json file must be present.
"""

Scenario: Scaffold package tests
Given a invalid-command/command.php file:
"""
Expand Down
29 changes: 17 additions & 12 deletions src/ScaffoldPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function package( $args, $assoc_args ) {
* ## OPTIONS
*
* <dir>
* : Directory of an existing command.
* : Directory path to an existing package to generate a readme for.
*
* [--force]
* : Overwrite the readme if it already exists.
Expand All @@ -194,9 +194,7 @@ public function package_readme( $args, $assoc_args ) {

list( $package_dir ) = $args;

if ( ! is_dir( $package_dir ) || ! file_exists( $package_dir . '/composer.json' ) ) {
WP_CLI::error( "Invalid package directory. composer.json file must be present." );
}
self::check_if_valid_package_dir( $package_dir );

$composer_obj = json_decode( file_get_contents( $package_dir . '/composer.json' ), true );
if ( ! $composer_obj ) {
Expand Down Expand Up @@ -384,7 +382,7 @@ public function package_readme( $args, $assoc_args ) {
* ## OPTIONS
*
* <dir>
* : The package directory to generate GitHub configuration for.
* : Directory path to an existing package to generate GitHub configuration for.
*
* [--force]
* : Overwrite files that already exist.
Expand All @@ -401,9 +399,8 @@ public function package_github( $args, $assoc_args ) {
$package_dir = rtrim( $package_dir, '/' );
}

if ( ! is_dir( $package_dir ) || ! file_exists( $package_dir . '/composer.json' ) ) {
WP_CLI::error( "Invalid package directory. composer.json file must be present." );
}
self::check_if_valid_package_dir( $package_dir );

$force = Utils\get_flag_value( $assoc_args, 'force' );
$template_path = dirname( dirname( __FILE__ ) ) . '/templates';

Expand Down Expand Up @@ -492,7 +489,7 @@ public function package_github( $args, $assoc_args ) {
* ## OPTIONS
*
* <dir>
* : The package directory to generate tests for.
* : Directory path to an existing package to generate tests for.
*
* [--ci=<provider>]
* : Create a configuration file for a specific CI provider.
Expand Down Expand Up @@ -522,9 +519,7 @@ public function package_tests( $args, $assoc_args ) {
$package_dir = rtrim( $package_dir, '/' );
}

if ( ! is_dir( $package_dir ) || ! file_exists( $package_dir . '/composer.json' ) ) {
WP_CLI::error( "Invalid package directory. composer.json file must be present." );
}
self::check_if_valid_package_dir( $package_dir );

$package_dir .= '/';
$bin_dir = $package_dir . 'bin/';
Expand Down Expand Up @@ -664,4 +659,14 @@ private function create_files( $files_and_contents, $force ) {
return $wrote_files;
}

private static function check_if_valid_package_dir( $package_dir ) {
if ( ! is_dir( $package_dir ) ) {
WP_CLI::error( 'Directory does not exist.' );
}

if ( ! file_exists( $package_dir . '/composer.json' ) ) {
WP_CLI::error( 'Invalid package directory. composer.json file must be present.' );
}
}

}