[route] Use generic option-parsing library
Total saving: 71 bytes. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
72b4464c89
commit
46116d8d03
@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <ipxe/command.h>
|
#include <ipxe/command.h>
|
||||||
|
#include <ipxe/parseopt.h>
|
||||||
#include <usr/route.h>
|
#include <usr/route.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
@ -29,52 +30,34 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/** "route" options */
|
||||||
* "route" command syntax message
|
struct route_options {};
|
||||||
*
|
|
||||||
* @v argv Argument list
|
/** "route" option list */
|
||||||
*/
|
static struct option_descriptor route_opts[] = {};
|
||||||
static void route_syntax ( char **argv ) {
|
|
||||||
printf ( "Usage:\n"
|
/** "route" command descriptor */
|
||||||
" %s\n"
|
static struct command_descriptor route_cmd =
|
||||||
"\n"
|
COMMAND_DESC ( struct route_options, route_opts, 0, 0,
|
||||||
"Displays the routing table\n",
|
"", "Display the routing table" );
|
||||||
argv[0] );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "route" command
|
* The "route" 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 route_exec ( int argc, char **argv ) {
|
static int route_exec ( int argc, char **argv ) {
|
||||||
static struct option longopts[] = {
|
struct route_options opts;
|
||||||
{ "help", 0, NULL, 'h' },
|
int rc;
|
||||||
{ NULL, 0, NULL, 0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
int c;
|
|
||||||
|
|
||||||
/* Parse options */
|
/* Parse options */
|
||||||
while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
|
if ( ( rc = parse_options ( argc, argv, &route_cmd, &opts ) ) != 0 )
|
||||||
switch ( c ) {
|
return rc;
|
||||||
case 'h':
|
|
||||||
/* Display help text */
|
|
||||||
default:
|
|
||||||
/* Unrecognised/invalid option */
|
|
||||||
route_syntax ( argv );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( optind != argc ) {
|
|
||||||
route_syntax ( argv );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
route();
|
route();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user