Skip to content

Commit 34863a5

Browse files
committedOct 25, 2012
[settings] Prefill existing setting value in "read" command
When prompting the user to enter a setting value via the "read" command, prefill the input buffer with the setting's current value. Requested-by: Ján Ondrej (SAL) <ondrejj@salstar.ks> Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent 4dedccf commit 34863a5

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed
 

‎src/hci/commands/nvo_cmd.c

+22-8
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ static struct command_descriptor clear_read_cmd =
109109
*/
110110
static int set_core_exec ( int argc, char **argv,
111111
struct command_descriptor *cmd,
112-
int ( * get_value ) ( char **args, char **value ) ) {
112+
int ( * get_value ) ( const char *name,
113+
char **args, char **value ) ) {
113114
struct set_core_options opts;
114115
const char *name;
115116
char *value;
@@ -123,7 +124,7 @@ static int set_core_exec ( int argc, char **argv,
123124
name = argv[optind];
124125

125126
/* Parse setting value */
126-
if ( ( rc = get_value ( &argv[ optind + 1 ], &value ) ) != 0 )
127+
if ( ( rc = get_value ( name, &argv[ optind + 1 ], &value ) ) != 0 )
127128
goto err_get_value;
128129

129130
/* Determine total length of command line */
@@ -147,11 +148,12 @@ static int set_core_exec ( int argc, char **argv,
147148
/**
148149
* Get setting value for "set" command
149150
*
151+
* @v name Setting name
150152
* @v args Remaining arguments
151153
* @ret value Setting value
152154
* @ret rc Return status code
153155
*/
154-
static int set_value ( char **args, char **value ) {
156+
static int set_value ( const char *name __unused, char **args, char **value ) {
155157

156158
*value = concat_args ( args );
157159
if ( ! *value )
@@ -174,11 +176,13 @@ static int set_exec ( int argc, char **argv ) {
174176
/**
175177
* Get setting value for "clear" command
176178
*
179+
* @v name Setting name
177180
* @v args Remaining arguments
178181
* @ret value Setting value
179182
* @ret rc Return status code
180183
*/
181-
static int clear_value ( char **args __unused, char **value ) {
184+
static int clear_value ( const char *name __unused, char **args __unused,
185+
char **value ) {
182186

183187
*value = NULL;
184188
return 0;
@@ -198,14 +202,24 @@ static int clear_exec ( int argc, char **argv ) {
198202
/**
199203
* Get setting value for "read" command
200204
*
205+
* @v name Setting name
206+
* @v args Remaining arguments
201207
* @ret value Setting value
202208
* @ret rc Return status code
203209
*/
204-
static int read_value ( char **args __unused, char **value ) {
210+
static int read_value ( const char *name, char **args __unused, char **value ) {
211+
char *existing;
212+
int rc;
205213

206-
*value = readline ( NULL );
207-
if ( ! *value )
208-
return -ENOMEM;
214+
/* Read existing value */
215+
if ( ( rc = fetchf_named_setting_copy ( name, &existing ) ) < 0 )
216+
return rc;
217+
218+
/* Read new value */
219+
*value = readline_history ( NULL, existing, NULL );
220+
221+
/* Free existing value */
222+
free ( existing );
209223

210224
return 0;
211225
}

0 commit comments

Comments
 (0)