(trunk) make --version/-V behave the same in the other apps too

This commit is contained in:
Charles Kerr
2010-08-09 00:18:26 +00:00
parent 0761c52e8d
commit c01c18b46b
5 changed files with 26 additions and 18 deletions

View File

@@ -67,6 +67,7 @@
#define MY_CONFIG_NAME "transmission"
#define MY_READABLE_NAME "transmission-cli"
static tr_bool showVersion = FALSE;
static tr_bool verify = 0;
static sig_atomic_t gotsig = 0;
static sig_atomic_t manualUpdate = 0;
@@ -91,6 +92,7 @@ static const struct tr_option options[] =
{ 'u', "uplimit", "Set max upload speed in "SPEED_K_STR, "u", 1, "<speed>" },
{ 'U', "no-uplimit", "Don't limit the upload speed", "U", 0, NULL },
{ 'v', "verify", "Verify the specified torrent", "v", 0, NULL },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 'w', "download-dir", "Where to save downloaded data", "w", 1, "<path>" },
{ 0, NULL, NULL, NULL, 0, NULL }
};
@@ -228,8 +230,14 @@ main( int argc, char ** argv )
tr_formatter_size_init( DISK_K,DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR );
tr_formatter_speed_init( SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR );
printf( "Transmission %s - http://www.transmissionbt.com/\n",
LONG_VERSION_STRING );
printf( "%s %s\n", MY_READABLE_NAME, LONG_VERSION_STRING );
/* the command line overrides defaults */
if( parseCommandLine( &settings, argc, (const char**)argv ) )
return EXIT_FAILURE;
if( showVersion )
return 0;
/* user needs to pass in at least one argument */
if( argc < 2 ) {
@@ -242,10 +250,6 @@ main( int argc, char ** argv )
configDir = getConfigDir( argc, (const char**)argv );
tr_sessionLoadSettings( &settings, configDir, MY_CONFIG_NAME );
/* the command line overrides defaults */
if( parseCommandLine( &settings, argc, (const char**)argv ) )
return EXIT_FAILURE;
/* Check the options for validity */
if( !torrentPath ) {
fprintf( stderr, "No torrent specified!\n" );
@@ -390,7 +394,9 @@ parseCommandLine( tr_benc * d, int argc, const char ** argv )
break;
case 'U': tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, FALSE );
break;
case 'v': verify = 1;
case 'v': verify = TRUE;
break;
case 'V': showVersion = TRUE;
break;
case 'w': tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR, optarg );
break;

View File

@@ -382,7 +382,7 @@ main( int argc, char ** argv )
case 'g': /* handled above */
break;
case 'V': /* version */
fprintf(stderr, "Transmission %s\n", LONG_VERSION_STRING);
fprintf(stderr, "%s %s\n", MY_NAME, LONG_VERSION_STRING);
exit( 0 );
case 'o': tr_bencDictAddBool( &settings, TR_PREFS_KEY_DHT_ENABLED, TRUE );
break;

View File

@@ -197,9 +197,9 @@ static const char*
getUsage( void )
{
return
"Transmission " LONG_VERSION_STRING
" http://www.transmissionbt.com/\n"
MY_NAME" "LONG_VERSION_STRING"\n"
"A fast and easy BitTorrent client\n"
"http://www.transmissionbt.com/\n"
"\n"
"Usage: " MY_NAME
" [host] [options]\n"
@@ -1828,7 +1828,7 @@ processArgs( const char * host, int port, int argc, const char ** argv )
break;
case 'V': /* show version number */
fprintf( stderr, "Transmission %s\n", LONG_VERSION_STRING );
fprintf( stderr, "%s %s\n", MY_NAME, LONG_VERSION_STRING );
exit( 0 );
break;

View File

@@ -550,7 +550,7 @@ main( int argc, char ** argv )
if( showversion )
{
fprintf( stderr, "%s %s\n", g_get_application_name( ), LONG_VERSION_STRING );
fprintf( stderr, "%s %s\n", MY_READABLE_NAME, LONG_VERSION_STRING );
return 0;
}

View File

@@ -49,7 +49,9 @@ namespace
const char * DBUS_OBJECT_PATH ( "/com/transmissionbt/Transmission" );
const char * DBUS_INTERFACE ( "com.transmissionbt.Transmission" );
const char * MY_NAME( "transmission" );
const char * MY_CONFIG_NAME( "transmission" );
const char * MY_READABLE_NAME( "transmission-qt" );
const tr_option opts[] =
{
@@ -73,7 +75,7 @@ namespace
void
showUsage( void )
{
tr_getopt_usage( MY_NAME, getUsage( ), opts );
tr_getopt_usage( MY_READABLE_NAME, getUsage( ), opts );
exit( 0 );
}
@@ -89,7 +91,7 @@ MyApp :: MyApp( int& argc, char ** argv ):
QApplication( argc, argv ),
myLastFullUpdateTime( 0 )
{
setApplicationName( MY_NAME );
setApplicationName( MY_CONFIG_NAME );
// install the qt translator
QTranslator qtTranslator;
@@ -98,7 +100,7 @@ MyApp :: MyApp( int& argc, char ** argv ):
// install the transmission translator
QTranslator appTranslator;
appTranslator.load( QString(MY_NAME) + "_" + QLocale::system().name() );
appTranslator.load( QString(MY_READABLE_NAME) + "_" + QLocale::system().name() );
installTranslator( &appTranslator );
Formatter::initUnits( );
@@ -130,7 +132,7 @@ MyApp :: MyApp( int& argc, char ** argv ):
case 'u': username = optarg; break;
case 'w': password = optarg; break;
case 'm': minimized = true; break;
case 'v': Utils::toStderr( QObject::tr( "transmission %1" ).arg( LONG_VERSION_STRING ) ); ::exit( 0 ); break;
case 'v': std::cerr << MY_READABLE_NAME << ' ' << LONG_VERSION_STRING << std::endl; ::exit( 0 ); break;
case TR_OPT_ERR: Utils::toStderr( QObject::tr( "Invalid option" ) ); showUsage( ); break;
default: filenames.append( optarg ); break;
}
@@ -138,7 +140,7 @@ MyApp :: MyApp( int& argc, char ** argv ):
// set the fallback config dir
if( configDir == 0 )
configDir = tr_getDefaultConfigDir( MY_NAME );
configDir = tr_getDefaultConfigDir( MY_CONFIG_NAME );
// is this the first time we've run transmission?
const bool firstTime = !QFile(QDir(configDir).absoluteFilePath("settings.json")).exists();