[san] Use generic option-parsing library
Total saving: 73 bytes. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
817c544697
commit
72b4464c89
|
@ -1,69 +1,77 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <ipxe/command.h>
|
#include <ipxe/command.h>
|
||||||
|
#include <ipxe/parseopt.h>
|
||||||
#include <usr/autoboot.h>
|
#include <usr/autoboot.h>
|
||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
/**
|
/** @file
|
||||||
* "sanboot" command syntax message
|
*
|
||||||
|
* SAN commands
|
||||||
*
|
*
|
||||||
* @v argv Argument list
|
|
||||||
*/
|
*/
|
||||||
static void sanboot_syntax ( char **argv ) {
|
|
||||||
printf ( "Usage:\n"
|
/** "sanboot" options */
|
||||||
" %s <root-path>\n"
|
struct sanboot_options {};
|
||||||
"\n"
|
|
||||||
"Boot from SAN target\n",
|
/** "sanboot" option list */
|
||||||
argv[0] );
|
static struct option_descriptor sanboot_opts[] = {};
|
||||||
}
|
|
||||||
|
/** "sanboot" command descriptor */
|
||||||
|
static struct command_descriptor sanboot_cmd =
|
||||||
|
COMMAND_DESC ( struct sanboot_options, sanboot_opts, 1, 1,
|
||||||
|
"<root-path>", "Boot from SAN target" );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "sanboot" command
|
* The "sanboot" command
|
||||||
*
|
*
|
||||||
* @v argc Argument count
|
* @v argc Argument count
|
||||||
* @v argv Argument list
|
* @v argv Argument list
|
||||||
* @ret rc Exit code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
static int sanboot_exec ( int argc, char **argv ) {
|
static int sanboot_exec ( int argc, char **argv ) {
|
||||||
static struct option longopts[] = {
|
struct sanboot_options opts;
|
||||||
{ "help", 0, NULL, 'h' },
|
const char *root_path;
|
||||||
{ NULL, 0, NULL, 0 },
|
|
||||||
};
|
|
||||||
const char *root_path = NULL;
|
|
||||||
int c;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Parse options */
|
/* Parse options */
|
||||||
while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
|
if ( ( rc = parse_options ( argc, argv, &sanboot_cmd, &opts ) ) != 0 )
|
||||||
switch ( c ) {
|
return rc;
|
||||||
case 'h':
|
|
||||||
/* Display help text */
|
|
||||||
default:
|
|
||||||
/* Unrecognised/invalid option */
|
|
||||||
sanboot_syntax ( argv );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Need exactly one image name remaining after the options */
|
/* Parse root path */
|
||||||
if ( optind != ( argc - 1 ) ) {
|
|
||||||
sanboot_syntax ( argv );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
root_path = argv[optind];
|
root_path = argv[optind];
|
||||||
|
|
||||||
/* Boot from root path */
|
/* Boot from root path */
|
||||||
if ( ( rc = boot_root_path ( root_path ) ) != 0 ) {
|
if ( ( rc = boot_root_path ( root_path ) ) != 0 ) {
|
||||||
printf ( "Could not boot from %s: %s\n",
|
printf ( "Could not boot from %s: %s\n",
|
||||||
root_path, strerror ( rc ) );
|
root_path, strerror ( rc ) );
|
||||||
return 1;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** SAN commands */
|
||||||
struct command sanboot_command __command = {
|
struct command sanboot_command __command = {
|
||||||
.name = "sanboot",
|
.name = "sanboot",
|
||||||
.exec = sanboot_exec,
|
.exec = sanboot_exec,
|
||||||
|
|
Reference in New Issue