Make all commands properly support --help and --version
These should output to stdout and exit with status 0. Passing std-options to AM_INIT_AUTOMAKE causes ‘make installcheck’ (hence also ‘make distcheck’) to verify this. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
committed by
John Hood
parent
e8f1004f94
commit
94027efc45
@@ -70,12 +70,18 @@
|
||||
# error "SysV or X/Open-compatible Curses header file required"
|
||||
#endif
|
||||
|
||||
static void usage( const char *argv0 ) {
|
||||
fprintf( stderr, "mosh-client (%s) [build %s]\n", PACKAGE_STRING, BUILD_VERSION );
|
||||
fprintf( stderr, "Copyright 2012 Keith Winstein <mosh-devel@mit.edu>\n" );
|
||||
fprintf( stderr, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\n" );
|
||||
static void print_version( FILE *file )
|
||||
{
|
||||
fprintf( file, "mosh-client (%s) [build %s]\n", PACKAGE_STRING, BUILD_VERSION );
|
||||
fprintf( file, "Copyright 2012 Keith Winstein <mosh-devel@mit.edu>\n" );
|
||||
fprintf( file, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n" );
|
||||
}
|
||||
|
||||
fprintf( stderr, "Usage: %s [-# 'ARGS'] IP PORT\n %s -c\n", argv0, argv0 );
|
||||
static void print_usage( FILE *file, const char *argv0 )
|
||||
{
|
||||
print_version( file );
|
||||
fprintf( file, "\n" );
|
||||
fprintf( file, "Usage: %s [-# 'ARGS'] IP PORT\n %s -c\n", argv0, argv0 );
|
||||
}
|
||||
|
||||
static void print_colorcount( void )
|
||||
@@ -107,6 +113,17 @@ int main( int argc, char *argv[] )
|
||||
fatal_assert( argc > 0 );
|
||||
|
||||
/* Get arguments */
|
||||
for ( int i = 1; i < argc; i++ ) {
|
||||
if ( 0 == strcmp( argv[ i ], "--help" ) ) {
|
||||
print_usage( stdout, argv[ 0 ] );
|
||||
exit( 0 );
|
||||
}
|
||||
if ( 0 == strcmp( argv[ i ], "--version" ) ) {
|
||||
print_version( stdout );
|
||||
exit( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
int opt;
|
||||
while ( (opt = getopt( argc, argv, "#:cv" )) != -1 ) {
|
||||
switch ( opt ) {
|
||||
@@ -121,7 +138,7 @@ int main( int argc, char *argv[] )
|
||||
verbose++;
|
||||
break;
|
||||
default:
|
||||
usage( argv[ 0 ] );
|
||||
print_usage( stderr, argv[ 0 ] );
|
||||
exit( 1 );
|
||||
break;
|
||||
}
|
||||
@@ -130,7 +147,7 @@ int main( int argc, char *argv[] )
|
||||
char *ip, *desired_port;
|
||||
|
||||
if ( argc - optind != 2 ) {
|
||||
usage( argv[ 0 ] );
|
||||
print_usage( stderr, argv[ 0 ] );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
@@ -141,7 +158,7 @@ int main( int argc, char *argv[] )
|
||||
if ( desired_port
|
||||
&& ( strspn( desired_port, "0123456789" ) != strlen( desired_port ) ) ) {
|
||||
fprintf( stderr, "%s: Bad UDP port (%s)\n\n", argv[ 0 ], desired_port );
|
||||
usage( argv[ 0 ] );
|
||||
print_usage( stderr, argv[ 0 ] );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user