Browse Source

[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>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
34863a51c2
1 changed files with 22 additions and 8 deletions
  1. 22
    8
      src/hci/commands/nvo_cmd.c

+ 22
- 8
src/hci/commands/nvo_cmd.c View File

109
  */
109
  */
110
 static int set_core_exec ( int argc, char **argv,
110
 static int set_core_exec ( int argc, char **argv,
111
 			   struct command_descriptor *cmd,
111
 			   struct command_descriptor *cmd,
112
-			   int ( * get_value ) ( char **args, char **value ) ) {
112
+			   int ( * get_value ) ( const char *name,
113
+						 char **args, char **value ) ) {
113
 	struct set_core_options opts;
114
 	struct set_core_options opts;
114
 	const char *name;
115
 	const char *name;
115
 	char *value;
116
 	char *value;
123
 	name = argv[optind];
124
 	name = argv[optind];
124
 
125
 
125
 	/* Parse setting value */
126
 	/* Parse setting value */
126
-	if ( ( rc = get_value ( &argv[ optind + 1 ], &value ) ) != 0 )
127
+	if ( ( rc = get_value ( name, &argv[ optind + 1 ], &value ) ) != 0 )
127
 		goto err_get_value;
128
 		goto err_get_value;
128
 
129
 
129
 	/* Determine total length of command line */
130
 	/* Determine total length of command line */
147
 /**
148
 /**
148
  * Get setting value for "set" command
149
  * Get setting value for "set" command
149
  *
150
  *
151
+ * @v name		Setting name
150
  * @v args		Remaining arguments
152
  * @v args		Remaining arguments
151
  * @ret value		Setting value
153
  * @ret value		Setting value
152
  * @ret rc		Return status code
154
  * @ret rc		Return status code
153
  */
155
  */
154
-static int set_value ( char **args, char **value ) {
156
+static int set_value ( const char *name __unused, char **args, char **value ) {
155
 
157
 
156
 	*value = concat_args ( args );
158
 	*value = concat_args ( args );
157
 	if ( ! *value )
159
 	if ( ! *value )
174
 /**
176
 /**
175
  * Get setting value for "clear" command
177
  * Get setting value for "clear" command
176
  *
178
  *
179
+ * @v name		Setting name
177
  * @v args		Remaining arguments
180
  * @v args		Remaining arguments
178
  * @ret value		Setting value
181
  * @ret value		Setting value
179
  * @ret rc		Return status code
182
  * @ret rc		Return status code
180
  */
183
  */
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 ) {
182
 
186
 
183
 	*value = NULL;
187
 	*value = NULL;
184
 	return 0;
188
 	return 0;
198
 /**
202
 /**
199
  * Get setting value for "read" command
203
  * Get setting value for "read" command
200
  *
204
  *
205
+ * @v name		Setting name
206
+ * @v args		Remaining arguments
201
  * @ret value		Setting value
207
  * @ret value		Setting value
202
  * @ret rc		Return status code
208
  * @ret rc		Return status code
203
  */
209
  */
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;
205
 
213
 
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 );
209
 
223
 
210
 	return 0;
224
 	return 0;
211
 }
225
 }

Loading…
Cancel
Save