From c4b254f8fd8d82662f8a0d0e2355f48ad13fa628 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 1 Jan 2008 18:14:05 +0000 Subject: [PATCH] (cli) Ticket #524: print version on the command line with --version or -v --- cli/transmissioncli.1 | 14 +++++++------- cli/transmissioncli.c | 24 +++++++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cli/transmissioncli.1 b/cli/transmissioncli.1 index 74988dce2..428cc56fb 100644 --- a/cli/transmissioncli.1 +++ b/cli/transmissioncli.1 @@ -24,15 +24,15 @@ .Bk -words .Fl h .Nm -.Op Fl v Ar level +.Op Fl v Ar [level] .Fl i .Ar torrent-file .Nm -.Op Fl v Ar level +.Op Fl v Ar [level] .Fl s .Ar torrent-file .Nm -.Op Fl v Ar level +.Op Fl v Ar [level] .Op Fl p Ar port .Op Fl d Ar download-rate .Op Fl u Ar upload-rate @@ -41,10 +41,10 @@ .Op Fl n .Ar torrent-file .Nm -.Op Fl v Ar level +.Op Fl v Ar [level] .Fl c Ar source-file .Fl a Ar announce-url -.Op Fl p Ar 1 +.Op Fl p Ar port .Op Fl m Ar comment .Ar output-file .Ek @@ -78,8 +78,8 @@ Uses the specified directory as destination for downloaded data. .It Fl s, -scrape Prints the number of seeders and leechers for the specified torrent file, and exits. -.It Fl v, -verbose Ar level -Sets debugging options. The current range is 0-2, with the highest +.It Fl v, -verbose Ar [level] +Sets debugging options. You can use both many -v flags, or a -v level. The current available levels are 0-2, with the highest level producing the most output. The default is 0. .It Fl n, Fl -nat-traversal Attempt to use the NAT-PMP and UPnP IGD protocols to establish a port diff --git a/cli/transmissioncli.c b/cli/transmissioncli.c index c64140c42..681ccd16d 100644 --- a/cli/transmissioncli.c +++ b/cli/transmissioncli.c @@ -56,11 +56,13 @@ const char * USAGE = " -s, --scrape Print counts of seeders/leechers and exit\n" " -u, --upload Maximum upload rate (-1 = no limit, default = 20)\n" " -v, --verbose Verbose level (0 to 2, default = 0)\n" +" -V, --version Print the version number and exit\n" " -y, --recheck Force a recheck of the torrent data\n"; static int showHelp = 0; static int showInfo = 0; static int showScrape = 0; +static int showVersion = 0; static int isPrivate = 0; static int verboseLevel = 0; static int bindPort = TR_DEFAULT_PORT; @@ -110,7 +112,7 @@ int main( int argc, char ** argv ) tr_handle_status * hstat; tr_ctor * ctor; - printf( "Transmission %s - http://www.transmissionbt.com/\n\n", + printf( "Transmission %s - http://www.transmissionbt.com/\n", LONG_VERSION_STRING ); /* Get options */ @@ -120,6 +122,9 @@ int main( int argc, char ** argv ) return EXIT_FAILURE; } + if( showVersion ) + return EXIT_SUCCESS; + if( showHelp ) { printf( USAGE, argv[0], TR_DEFAULT_PORT ); @@ -360,7 +365,8 @@ cleanup: return EXIT_SUCCESS; } -static int parseCommandLine( int argc, char ** argv ) +static int +parseCommandLine( int argc, char ** argv ) { for( ;; ) { @@ -369,6 +375,7 @@ static int parseCommandLine( int argc, char ** argv ) { "info", no_argument, NULL, 'i' }, { "scrape", no_argument, NULL, 's' }, { "private", no_argument, NULL, 'r' }, + { "version", no_argument, NULL, 'V' }, { "verbose", required_argument, NULL, 'v' }, { "port", required_argument, NULL, 'p' }, { "upload", required_argument, NULL, 'u' }, @@ -383,7 +390,7 @@ static int parseCommandLine( int argc, char ** argv ) { 0, 0, 0, 0} }; int c, optind = 0; - c = getopt_long( argc, argv, "hisrv:p:u:d:f:c:m:a:no:y", + c = getopt_long( argc, argv, "hisrVv:p:u:d:f:c:m:a:no:y", long_options, &optind ); if( c < 0 ) { @@ -406,6 +413,9 @@ static int parseCommandLine( int argc, char ** argv ) case 'v': verboseLevel = atoi( optarg ); break; + case 'V': + showVersion = 1; + break; case 'p': bindPort = atoi( optarg ); break; @@ -440,13 +450,13 @@ static int parseCommandLine( int argc, char ** argv ) } } + if( showHelp || showVersion ) + return 0; + if( optind >= argc ) - { - return !showHelp; - } + return 1; torrentPath = argv[optind]; - return 0; }