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
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
AC_PREREQ([2.61])
|
AC_PREREQ([2.61])
|
||||||
AC_INIT([mosh], [1.2.6], [mosh-devel@mit.edu])
|
AC_INIT([mosh], [1.2.6], [mosh-devel@mit.edu])
|
||||||
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
|
AM_INIT_AUTOMAKE([foreign std-options -Wall -Werror])
|
||||||
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
|
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
|
||||||
AC_CONFIG_SRCDIR([src/frontend/mosh-client.cc])
|
AC_CONFIG_SRCDIR([src/frontend/mosh-client.cc])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|||||||
+8
-2
@@ -166,8 +166,14 @@ GetOptions( 'client=s' => \$client,
|
|||||||
'bind-server=s' => \$bind_ip,
|
'bind-server=s' => \$bind_ip,
|
||||||
'experimental-remote-ip=s' => \$use_remote_ip) or die $usage;
|
'experimental-remote-ip=s' => \$use_remote_ip) or die $usage;
|
||||||
|
|
||||||
die $usage if ( defined $help );
|
if ( defined $help ) {
|
||||||
die $version_message if ( defined $version );
|
print $usage;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if ( defined $version ) {
|
||||||
|
print $version_message;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if ( defined $predict ) {
|
if ( defined $predict ) {
|
||||||
predict_check( $predict, 0 );
|
predict_check( $predict, 0 );
|
||||||
|
|||||||
@@ -70,12 +70,18 @@
|
|||||||
# error "SysV or X/Open-compatible Curses header file required"
|
# error "SysV or X/Open-compatible Curses header file required"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void usage( const char *argv0 ) {
|
static void print_version( FILE *file )
|
||||||
fprintf( stderr, "mosh-client (%s) [build %s]\n", PACKAGE_STRING, BUILD_VERSION );
|
{
|
||||||
fprintf( stderr, "Copyright 2012 Keith Winstein <mosh-devel@mit.edu>\n" );
|
fprintf( file, "mosh-client (%s) [build %s]\n", PACKAGE_STRING, BUILD_VERSION );
|
||||||
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" );
|
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 )
|
static void print_colorcount( void )
|
||||||
@@ -107,6 +113,17 @@ int main( int argc, char *argv[] )
|
|||||||
fatal_assert( argc > 0 );
|
fatal_assert( argc > 0 );
|
||||||
|
|
||||||
/* Get arguments */
|
/* 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;
|
int opt;
|
||||||
while ( (opt = getopt( argc, argv, "#:cv" )) != -1 ) {
|
while ( (opt = getopt( argc, argv, "#:cv" )) != -1 ) {
|
||||||
switch ( opt ) {
|
switch ( opt ) {
|
||||||
@@ -121,7 +138,7 @@ int main( int argc, char *argv[] )
|
|||||||
verbose++;
|
verbose++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage( argv[ 0 ] );
|
print_usage( stderr, argv[ 0 ] );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -130,7 +147,7 @@ int main( int argc, char *argv[] )
|
|||||||
char *ip, *desired_port;
|
char *ip, *desired_port;
|
||||||
|
|
||||||
if ( argc - optind != 2 ) {
|
if ( argc - optind != 2 ) {
|
||||||
usage( argv[ 0 ] );
|
print_usage( stderr, argv[ 0 ] );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +158,7 @@ int main( int argc, char *argv[] )
|
|||||||
if ( desired_port
|
if ( desired_port
|
||||||
&& ( strspn( desired_port, "0123456789" ) != strlen( desired_port ) ) ) {
|
&& ( strspn( desired_port, "0123456789" ) != strlen( desired_port ) ) ) {
|
||||||
fprintf( stderr, "%s: Bad UDP port (%s)\n\n", argv[ 0 ], 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 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,13 @@ static int run_server( const char *desired_ip, const char *desired_port,
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static void print_version( FILE *file )
|
||||||
|
{
|
||||||
|
fprintf( file, "mosh-server (%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" );
|
||||||
|
}
|
||||||
|
|
||||||
static void print_usage( FILE *stream, const char *argv0 )
|
static void print_usage( FILE *stream, const char *argv0 )
|
||||||
{
|
{
|
||||||
fprintf( stream, "Usage: %s new [-s] [-v] [-i LOCALADDR] [-p PORT[:PORT2]] [-c COLORS] [-l NAME=VALUE] [-- COMMAND...]\n", argv0 );
|
fprintf( stream, "Usage: %s new [-s] [-v] [-i LOCALADDR] [-p PORT[:PORT2]] [-c COLORS] [-l NAME=VALUE] [-- COMMAND...]\n", argv0 );
|
||||||
@@ -176,11 +183,15 @@ int main( int argc, char *argv[] )
|
|||||||
list<string> locale_vars;
|
list<string> locale_vars;
|
||||||
|
|
||||||
/* strip off command */
|
/* strip off command */
|
||||||
for ( int i = 0; i < argc; i++ ) {
|
for ( int i = 1; i < argc; i++ ) {
|
||||||
if ( 0 == strcmp( argv[ i ], "--help" ) || 0 == strcmp( argv[ i ], "-h" ) ) {
|
if ( 0 == strcmp( argv[ i ], "--help" ) || 0 == strcmp( argv[ i ], "-h" ) ) {
|
||||||
print_usage( stdout, argv[ 0 ] );
|
print_usage( stdout, argv[ 0 ] );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
if ( 0 == strcmp( argv[ i ], "--version" ) ) {
|
||||||
|
print_version( stdout );
|
||||||
|
exit( 0 );
|
||||||
|
}
|
||||||
if ( 0 == strcmp( argv[ i ], "--" ) ) { /* -- is mandatory */
|
if ( 0 == strcmp( argv[ i ], "--" ) ) { /* -- is mandatory */
|
||||||
if ( i != argc - 1 ) {
|
if ( i != argc - 1 ) {
|
||||||
command_argv = argv + i + 1;
|
command_argv = argv + i + 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user