Explorar el Código

[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 hace 12 años
padre
commit
34863a51c2
Se han modificado 1 ficheros con 22 adiciones y 8 borrados
  1. 22
    8
      src/hci/commands/nvo_cmd.c

+ 22
- 8
src/hci/commands/nvo_cmd.c Ver fichero

@@ -109,7 +109,8 @@ static struct command_descriptor clear_read_cmd =
109 109
  */
110 110
 static int set_core_exec ( int argc, char **argv,
111 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 114
 	struct set_core_options opts;
114 115
 	const char *name;
115 116
 	char *value;
@@ -123,7 +124,7 @@ static int set_core_exec ( int argc, char **argv,
123 124
 	name = argv[optind];
124 125
 
125 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 128
 		goto err_get_value;
128 129
 
129 130
 	/* Determine total length of command line */
@@ -147,11 +148,12 @@ static int set_core_exec ( int argc, char **argv,
147 148
 /**
148 149
  * Get setting value for "set" command
149 150
  *
151
+ * @v name		Setting name
150 152
  * @v args		Remaining arguments
151 153
  * @ret value		Setting value
152 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 158
 	*value = concat_args ( args );
157 159
 	if ( ! *value )
@@ -174,11 +176,13 @@ static int set_exec ( int argc, char **argv ) {
174 176
 /**
175 177
  * Get setting value for "clear" command
176 178
  *
179
+ * @v name		Setting name
177 180
  * @v args		Remaining arguments
178 181
  * @ret value		Setting value
179 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 187
 	*value = NULL;
184 188
 	return 0;
@@ -198,14 +202,24 @@ static int clear_exec ( int argc, char **argv ) {
198 202
 /**
199 203
  * Get setting value for "read" command
200 204
  *
205
+ * @v name		Setting name
206
+ * @v args		Remaining arguments
201 207
  * @ret value		Setting value
202 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 224
 	return 0;
211 225
 }

Loading…
Cancelar
Guardar