(trunk utils) add support for --version/-V

This commit is contained in:
Charles Kerr 2010-08-08 22:53:24 +00:00
parent cbf51842c8
commit ac9dd13ee0
3 changed files with 34 additions and 5 deletions

View File

@ -17,6 +17,7 @@
#include <libtransmission/makemeta.h>
#include <libtransmission/tr-getopt.h>
#include <libtransmission/utils.h>
#include <libtransmission/version.h>
#define MY_NAME "transmission-create"
@ -24,6 +25,7 @@
static tr_tracker_info trackers[MAX_TRACKERS];
static int trackerCount = 0;
static tr_bool isPrivate = FALSE;
static tr_bool showVersion = FALSE;
const char * comment = NULL;
const char * outfile = NULL;
const char * infile = NULL;
@ -34,6 +36,7 @@ static tr_option options[] =
{ 'o', "outfile", "Save the generated .torrent to this filename", "o", 1, "<file>" },
{ 'c', "comment", "Add a comment", "c", 1, "<comment>" },
{ 't', "tracker", "Add a tracker's announce URL", "t", 1, "<url>" },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 0, NULL, NULL, NULL, 0, NULL }
};
@ -53,6 +56,7 @@ parseCommandLine( int argc, const char ** argv )
{
switch( c )
{
case 'V': showVersion = TRUE; break;
case 'p': isPrivate = TRUE; break;
case 'o': outfile = optarg; break;
case 'c': comment = optarg; break;
@ -94,6 +98,11 @@ main( int argc, char * argv[] )
if( parseCommandLine( argc, (const char**)argv ) )
return EXIT_FAILURE;
if( showVersion ) {
fprintf( stderr, MY_NAME" "LONG_VERSION_STRING"\n" );
return 0;
}
if( !infile )
{
fprintf( stderr, "ERROR: No input file or directory specified.\n" );

View File

@ -18,20 +18,23 @@
#include <libtransmission/bencode.h>
#include <libtransmission/tr-getopt.h>
#include <libtransmission/utils.h>
#include <libtransmission/version.h>
#define MY_NAME "transmission-edit"
int fileCount = 0;
const char ** files = NULL;
const char * add = NULL;
const char * deleteme = NULL;
const char * replace[2] = { NULL, NULL };
static int fileCount = 0;
static tr_bool showVersion = FALSE;
static const char ** files = NULL;
static const char * add = NULL;
static const char * deleteme = NULL;
static const char * replace[2] = { NULL, NULL };
static tr_option options[] =
{
{ 'a', "add", "Add a tracker's announce URL", "a", 1, "<url>" },
{ 'd', "delete", "Delete a tracker's announce URL", "d", 1, "<url>" },
{ 'r', "replace", "Search and replace a substring in the announce URLs", "r", 1, "<old> <new>" },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 0, NULL, NULL, NULL, 0, NULL }
};
@ -60,6 +63,8 @@ parseCommandLine( int argc, const char ** argv )
if( c != TR_OPT_UNK ) return 1;
replace[1] = optarg;
break;
case 'V': showVersion = TRUE;
break;
case TR_OPT_UNK: files[fileCount++] = optarg; break;
default: return 1;
}
@ -258,6 +263,12 @@ main( int argc, char * argv[] )
if( parseCommandLine( argc, (const char**)argv ) )
return EXIT_FAILURE;
if( showVersion )
{
fprintf( stderr, MY_NAME" "LONG_VERSION_STRING"\n" );
return 0;
}
if( fileCount < 1 )
{
fprintf( stderr, "ERROR: No torrent files specified.\n" );

View File

@ -51,6 +51,7 @@
static tr_option options[] =
{
{ 's', "scrape", "Ask the torrent's trackers how many peers are in the torrent's swarm", "s", 0, NULL },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 0, NULL, NULL, NULL, 0, NULL }
};
@ -61,6 +62,7 @@ getUsage( void )
}
static tr_bool scrapeFlag = FALSE;
static tr_bool showVersion = FALSE;
const char * filename = NULL;
static int
@ -74,6 +76,7 @@ parseCommandLine( int argc, const char ** argv )
switch( c )
{
case 's': scrapeFlag = TRUE; break;
case 'V': showVersion = TRUE; break;
case TR_OPT_UNK: filename = optarg; break;
default: return 1;
}
@ -258,6 +261,12 @@ main( int argc, char * argv[] )
if( parseCommandLine( argc, (const char**)argv ) )
return EXIT_FAILURE;
if( showVersion )
{
fprintf( stderr, MY_NAME" "LONG_VERSION_STRING"\n" );
return 0;
}
/* make sure the user specified a filename */
if( !filename )
{