Skip to content

Commit be6637a

Browse files
committed
Merge branch 'vishalkakadiya-fix/remove-prompt-param' into develop
2 parents b055345 + 42dd016 commit be6637a

File tree

2 files changed

+0
-160
lines changed

2 files changed

+0
-160
lines changed

php/EE/Dispatcher/Subcommand.php

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -105,151 +105,6 @@ public function get_usage( $prefix ) {
105105
);
106106
}
107107

108-
/**
109-
* Wrapper for CLI Tools' prompt() method.
110-
*
111-
* @param string $question
112-
* @param string $default
113-
* @return string|false
114-
*/
115-
private function prompt( $question, $default ) {
116-
117-
$question .= ': ';
118-
if ( function_exists( 'readline' ) ) {
119-
return readline( $question );
120-
}
121-
122-
echo $question;
123-
124-
$ret = stream_get_line( STDIN, 1024, "\n" );
125-
if ( Utils\is_windows() && "\r" === substr( $ret, -1 ) ) {
126-
$ret = substr( $ret, 0, -1 );
127-
}
128-
return $ret;
129-
}
130-
131-
/**
132-
* Interactively prompt the user for input
133-
* based on defined synopsis and passed arguments.
134-
*
135-
* @param array $args
136-
* @param array $assoc_args
137-
* @return array
138-
*/
139-
private function prompt_args( $args, $assoc_args ) {
140-
141-
$synopsis = $this->get_synopsis();
142-
143-
if ( ! $synopsis ) {
144-
return array( $args, $assoc_args );
145-
}
146-
147-
$spec = array_filter(
148-
\EE\SynopsisParser::parse( $synopsis ),
149-
function( $spec_arg ) {
150-
return in_array( $spec_arg['type'], array( 'generic', 'positional', 'assoc', 'flag' ) );
151-
}
152-
);
153-
154-
$spec = array_values( $spec );
155-
156-
$prompt_args = EE::get_config( 'prompt' );
157-
if ( true !== $prompt_args ) {
158-
$prompt_args = explode( ',', $prompt_args );
159-
}
160-
161-
// 'positional' arguments are positional (aka zero-indexed)
162-
// so $args needs to be reset before prompting for new arguments
163-
$args = array();
164-
foreach ( $spec as $key => $spec_arg ) {
165-
166-
// When prompting for specific arguments (e.g. --prompt=user_pass),
167-
// ignore all arguments that don't match.
168-
if ( is_array( $prompt_args ) ) {
169-
if ( 'assoc' !== $spec_arg['type'] ) {
170-
continue;
171-
}
172-
if ( ! in_array( $spec_arg['name'], $prompt_args, true ) ) {
173-
continue;
174-
}
175-
}
176-
177-
$current_prompt = ( $key + 1 ) . '/' . count( $spec ) . ' ';
178-
$default = $spec_arg['optional'] ? '' : false;
179-
180-
// 'generic' permits arbitrary key=value (e.g. [--<field>=<value>] )
181-
if ( 'generic' == $spec_arg['type'] ) {
182-
183-
list( $key_token, $value_token ) = explode( '=', $spec_arg['token'] );
184-
185-
$repeat = false;
186-
do {
187-
if ( ! $repeat ) {
188-
$key_prompt = $current_prompt . $key_token;
189-
} else {
190-
$key_prompt = str_repeat( ' ', strlen( $current_prompt ) ) . $key_token;
191-
}
192-
193-
$key = $this->prompt( $key_prompt, $default );
194-
if ( false === $key ) {
195-
return array( $args, $assoc_args );
196-
}
197-
198-
if ( $key ) {
199-
$key_prompt_count = strlen( $key_prompt ) - strlen( $value_token ) - 1;
200-
$value_prompt = str_repeat( ' ', $key_prompt_count ) . '=' . $value_token;
201-
202-
$value = $this->prompt( $value_prompt, $default );
203-
if ( false === $value ) {
204-
return array( $args, $assoc_args );
205-
}
206-
207-
$assoc_args[ $key ] = $value;
208-
209-
$repeat = true;
210-
} else {
211-
$repeat = false;
212-
}
213-
} while ( $repeat );
214-
215-
} else {
216-
217-
$prompt = $current_prompt . $spec_arg['token'];
218-
if ( 'flag' == $spec_arg['type'] ) {
219-
$prompt .= ' (Y/n)';
220-
}
221-
222-
$response = $this->prompt( $prompt, $default );
223-
if ( false === $response ) {
224-
return array( $args, $assoc_args );
225-
}
226-
227-
if ( $response ) {
228-
switch ( $spec_arg['type'] ) {
229-
case 'positional':
230-
if ( $spec_arg['repeating'] ) {
231-
$response = explode( ' ', $response );
232-
} else {
233-
$response = array( $response );
234-
}
235-
$args = array_merge( $args, $response );
236-
break;
237-
case 'assoc':
238-
$assoc_args[ $spec_arg['name'] ] = $response;
239-
break;
240-
case 'flag':
241-
if ( 'Y' == strtoupper( $response ) ) {
242-
$assoc_args[ $spec_arg['name'] ] = true;
243-
}
244-
break;
245-
}
246-
}
247-
}
248-
}
249-
250-
return array( $args, $assoc_args );
251-
}
252-
253108
/**
254109
* Validate the supplied arguments to the command.
255110
* Throws warnings or errors if arguments are missing
@@ -382,19 +237,11 @@ private function validate_args( $args, $assoc_args, $extra_args ) {
382237

383238
/**
384239
* Invoke the subcommand with the supplied arguments.
385-
* Given a --prompt argument, interactively request input
386-
* from the end user.
387240
*
388241
* @param array $args
389242
* @param array $assoc_args
390243
*/
391244
public function invoke( $args, $assoc_args, $extra_args ) {
392-
static $prompted_once = false;
393-
if ( \EE::get_config( 'prompt' ) && ! $prompted_once ) {
394-
list( $_args, $assoc_args ) = $this->prompt_args( $args, $assoc_args );
395-
$args = array_merge( $args, $_args );
396-
$prompted_once = true;
397-
}
398245

399246
$extra_positionals = array();
400247
foreach ( $extra_args as $k => $v ) {

php/config-spec.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@
5151
'desc' => 'Show all PHP errors; add verbosity to EE bootstrap.',
5252
),
5353

54-
'prompt' => array(
55-
'runtime' => '[=<assoc>]',
56-
'file' => false,
57-
'default' => false,
58-
'desc' => 'Prompt the user to enter values for all command arguments, or a subset specified as comma-separated values.',
59-
),
60-
6154
'quiet' => array(
6255
'runtime' => '',
6356
'file' => '<bool>',

0 commit comments

Comments
 (0)