diff options
author | Michael Brown | 2010-11-22 21:41:17 +0100 |
---|---|---|
committer | Michael Brown | 2010-11-22 21:41:52 +0100 |
commit | ba92a46710481b968367460fe9a57a2567095bc9 (patch) | |
tree | ea9008de93848607c996a13970aba586f87df413 /src/core/exec.c | |
parent | [script] Allow "exit" to exit a script (diff) | |
download | ipxe-ba92a46710481b968367460fe9a57a2567095bc9.tar.gz ipxe-ba92a46710481b968367460fe9a57a2567095bc9.tar.xz ipxe-ba92a46710481b968367460fe9a57a2567095bc9.zip |
[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>
Diffstat (limited to 'src/core/exec.c')
-rw-r--r-- | src/core/exec.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/core/exec.c b/src/core/exec.c index 60d8cb97..f65a4647 100644 --- a/src/core/exec.c +++ b/src/core/exec.c @@ -381,3 +381,38 @@ struct command exit_command __command = { .exec = exit_exec, }; +/** "isset" options */ +struct isset_options {}; + +/** "isset" option list */ +static struct option_descriptor isset_opts[] = {}; + +/** "isset" command descriptor */ +static struct command_descriptor isset_cmd = + COMMAND_DESC ( struct isset_options, isset_opts, 0, MAX_ARGUMENTS, + "[...]", "" ); + +/** + * "isset" command + * + * @v argc Argument count + * @v argv Argument list + * @ret rc Return status code + */ +static int isset_exec ( int argc, char **argv ) { + struct isset_options opts; + int rc; + + /* Parse options */ + if ( ( rc = parse_options ( argc, argv, &isset_cmd, &opts ) ) != 0 ) + return rc; + + /* Return success iff any arguments exist */ + return ( ( optind == argc ) ? -ENOENT : 0 ); +} + +/** "isset" command */ +struct command isset_command __command = { + .name = "isset", + .exec = isset_exec, +}; |