Skip to content

Commit

Permalink
Add support for command level short form options (#286)
Browse files Browse the repository at this point in the history
Tests have passed locally. #287 is still causing problems on workflow testing. PHPCS is fine.

* Add support for command level short form options
Support short form options in commands and status command.

* Add other short options as suggested.
  • Loading branch information
yorkshire-pudding authored Jun 26, 2023
1 parent 86b2f4e commit db0a8c1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions commands/download.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ function download_bee_command() {
'options' => array(
'hide-progress' => array(
'description' => bt('Hide the download progress bar.'),
'short' => 'h',
),
'allow-multisite-copy' => array(
'description' => bt('Override the check that would prevent the project being downloaded to a multisite site if the project exists in the shared project directory.'),
'short' => 'f',
),
),
'aliases' => array('dl', 'pm-download'),
Expand All @@ -44,6 +46,7 @@ function download_bee_command() {
'options' => array(
'hide-progress' => array(
'description' => bt('Hide the download progress bar.'),
'short' => 'h',
),
),
'aliases' => array('dl-core'),
Expand Down
4 changes: 3 additions & 1 deletion commands/help.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ function help_bee_command_help(array $descriptor) {
$rows = array();
foreach ($descriptor['options'] as $option_name => $option) {
$value = !empty($option['value']) ? '=' . strtoupper($option['value']) : '';

if (isset($option['short'])) {
$option_name .= ', -' . $option['short'];
}
$rows[] = array(
array(
'value' => '--' . $option_name . $value,
Expand Down
2 changes: 2 additions & 0 deletions commands/install.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ function install_bee_command() {
),
'no-clean-urls' => array(
'description' => bt('Disable clean URLs.'),
'short' >= 'n',
),
'auto' => array(
'description' => bt('Perform an automatic (i.e. non-interactive) installation. Any options not explicitly provided to the command will use default values, except the database connection string which will always prompt when not provided.'),
'short' >= 'a',
),
),
'aliases' => array('si', 'site-install'),
Expand Down
3 changes: 3 additions & 0 deletions commands/projects.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function projects_bee_command() {
'options' => array(
'no-dependency-checking' => array(
'description' => bt('Disable dependency-checking and enable module(s) regardless. This could cause problems if there are missing dependencies. Use with caution.'),
'short' >= 'n',
),
),
'aliases' => array('en', 'pm-enable'),
Expand All @@ -63,6 +64,7 @@ function projects_bee_command() {
'options' => array(
'no-dependency-checking' => array(
'description' => bt('Disable dependency-checking and disable module(s) regardless. This could cause problems if there are other enabled modules that depend on this one. Use with caution.'),
'short' >= 'n',
),
),
'aliases' => array('dis', 'pm-disable'),
Expand All @@ -84,6 +86,7 @@ function projects_bee_command() {
'options' => array(
'no-dependency-checking' => array(
'description' => bt('Disable dependency-checking and uninstall module(s) regardless. This could cause problems if there are other installed modules that depend on this one. Use with caution.'),
'short' >= 'n',
),
),
'aliases' => array('pmu', 'pm-uninstall'),
Expand Down
4 changes: 3 additions & 1 deletion commands/status.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function status_bee_command() {
'options' => array(
'show-password' => array(
'description' => bt('Show the database password.'),
'short' => 'p',
),
),
'aliases' => array('st', 'info', 'core-status'),
Expand Down Expand Up @@ -81,9 +82,10 @@ function status_bee_callback($arguments, $options) {
array('value' => bt('Database username')),
array('value' => rawurldecode($info['username'])),
);
$status_show_password = (isset($options['show-password']) || isset($options['p']));
$rows[] = array(
array('value' => bt('Database password')),
array('value' => isset($options['show-password']) ? rawurldecode($info['password']) : '**********'),
array('value' => $status_show_password ? rawurldecode($info['password']) : '**********'),
);
$rows[] = array(
array('value' => bt('Database host')),
Expand Down
9 changes: 8 additions & 1 deletion includes/command.inc
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,15 @@ function bee_validate_command(array $descriptor) {
if (isset($descriptor['options'])) {
// Remove any provided options that aren't used by the command.
foreach ($_bee_options as $name => $value) {
// Check for long form command options.
if (!isset($descriptor['options'][$name])) {
unset($_bee_options[$name]);
// Check for short form command options.
foreach ($descriptor['options'] as $command_option) {
if (!isset($command_option['short']) || $command_option['short'] != $name) {
// Remove any that don't match either long or short form options.
unset($_bee_options[$name]);
}
}
}
}
}
Expand Down

0 comments on commit db0a8c1

Please sign in to comment.