Browse Source

[cmdline] Add "isset" command

The "isset" command can be used to determine whether or not a setting
is present.  For example:

  isset ${net0/ip} || dhcp net0   # If we have no IP address, try DHCP

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
ba92a46710
1 changed files with 35 additions and 0 deletions
  1. 35
    0
      src/core/exec.c

+ 35
- 0
src/core/exec.c View File

@@ -381,3 +381,38 @@ struct command exit_command __command = {
381 381
 	.exec = exit_exec,
382 382
 };
383 383
 
384
+/** "isset" options */
385
+struct isset_options {};
386
+
387
+/** "isset" option list */
388
+static struct option_descriptor isset_opts[] = {};
389
+
390
+/** "isset" command descriptor */
391
+static struct command_descriptor isset_cmd =
392
+	COMMAND_DESC ( struct isset_options, isset_opts, 0, MAX_ARGUMENTS,
393
+		       "[...]", "" );
394
+
395
+/**
396
+ * "isset" command
397
+ *
398
+ * @v argc		Argument count
399
+ * @v argv		Argument list
400
+ * @ret rc		Return status code
401
+ */
402
+static int isset_exec ( int argc, char **argv ) {
403
+	struct isset_options opts;
404
+	int rc;
405
+
406
+	/* Parse options */
407
+	if ( ( rc = parse_options ( argc, argv, &isset_cmd, &opts ) ) != 0 )
408
+		return rc;
409
+
410
+	/* Return success iff any arguments exist */
411
+	return ( ( optind == argc ) ? -ENOENT : 0 );
412
+}
413
+
414
+/** "isset" command */
415
+struct command isset_command __command = {
416
+	.name = "isset",
417
+	.exec = isset_exec,
418
+};

Loading…
Cancel
Save