From: Greg Kroah-Hartman Date: Wed, 19 May 2010 19:07:45 +0000 (-0700) Subject: Add ability to override default config file option X-Git-Url: https://git.toastfreeware.priv.at/gregoa/bti.git/commitdiff_plain/dada77e4c70f76bf581b3efc6821773d28b4425c Add ability to override default config file option Thanks to Reuben Thomas for this idea. Signed-off-by: Greg Kroah-Hartman --- diff --git a/bti.1 b/bti.1 index 0e3107f..971b3b0 100644 --- a/bti.1 +++ b/bti.1 @@ -22,7 +22,7 @@ bti \- send a tweet to twitter\&.com or identi\&.ca from the command line .SH "SYNOPSIS" .HP \w'\fBbti\fR\ 'u -\fBbti\fR [\fB\-\-account\ account\fR] [\fB\-\-password\ password\fR] [\fB\-\-action\ action\fR] [\fB\-\-user\ screenname\fR] [\fB\-\-host\ HOST_NAME\fR] [\fB\-\-proxy\ PROXY:PORT\fR] [\fB\-\-logfile\ LOGFILE\fR] [\fB\-\-page\ PAGENUMBER\fR] [\fB\-\-bash\fR] [\fB\-\-shrink\-urls\fR] [\fB\-\-debug\fR] [\fB\-\-dry\-run\fR] [\fB\-\-verbose\fR] [\fB\-\-version\fR] [\fB\-\-help\fR] +\fBbti\fR [\fB\-\-account\ account\fR] [\fB\-\-password\ password\fR] [\fB\-\-action\ action\fR] [\fB\-\-user\ screenname\fR] [\fB\-\-host\ HOST_NAME\fR] [\fB\-\-proxy\ PROXY:PORT\fR] [\fB\-\-logfile\ LOGFILE\fR] [\fB\-\-config\ CONFIGFILE\fR] [\fB\-\-page\ PAGENUMBER\fR] [\fB\-\-bash\fR] [\fB\-\-shrink\-urls\fR] [\fB\-\-debug\fR] [\fB\-\-dry\-run\fR] [\fB\-\-verbose\fR] [\fB\-\-version\fR] [\fB\-\-help\fR] .SH "DESCRIPTION" .PP bti sends a tweet message to twitter\&.com or identi\&.ca\&. @@ -67,6 +67,11 @@ If \-\-proxy is not specified but the environment variable \'http_proxy\' is set Specify a logfile for bti to write status messages to\&. LOGFILE is in relation to the user\'s home directory, not an absolute path to a file\&. .RE .PP +\fB\-\-config CONFIGFILE\fR +.RS 4 +Specify a config file for bti to read from\&. By default, bti looks in the ~/\&.bti file for config values\&. This default location can be overridden by setting a specific file with this option\&. +.RE +.PP \fB\-\-shrink\-urls\fR .RS 4 Scans the tweet text for valid URL patterns and passes each through the supplied bti\-shrink\-urls script\&. The script will pass the URL to a web service that shrinks the URLs, making it more suitable for micro\-blogging\&. @@ -192,7 +197,7 @@ config file option environment variables .RE .PP -For example, command line options always override any config file option, or any environment variables\&. +For example, command line options always override any config file option, or any environment variables\&. Unless a config file is specified by the command line\&. At that point, the new config file is read, and any previous options set by a command line option, would be overridden\&. .SH "AUTHOR" .PP Written by Greg Kroah\-Hartman and Amir Mohammad Saied \&. diff --git a/bti.c b/bti.c index 873e4f4..4bf6a6c 100644 --- a/bti.c +++ b/bti.c @@ -117,6 +117,7 @@ static void display_help(void) fprintf(stdout, " --proxy PROXY:PORT\n"); fprintf(stdout, " --host HOST\n"); fprintf(stdout, " --logfile logfile\n"); + fprintf(stdout, " --config configfile\n"); fprintf(stdout, " --shrink-urls\n"); fprintf(stdout, " --page PAGENUMBER\n"); fprintf(stdout, " --bash\n"); @@ -1059,6 +1060,7 @@ int main(int argc, char *argv[], char *envp[]) { "dry-run", 0, NULL, 'n' }, { "page", 1, NULL, 'g' }, { "version", 0, NULL, 'v' }, + { "config", 1, NULL, 'c' }, { } }; struct session *session; @@ -1107,7 +1109,7 @@ int main(int argc, char *argv[], char *envp[]) parse_configfile(session); while (1) { - option = getopt_long_only(argc, argv, "dp:P:H:a:A:u:hg:G:snVv", + option = getopt_long_only(argc, argv, "dp:P:H:a:A:u:c:hg:G:snVv", options, NULL); if (option == -1) break; @@ -1203,6 +1205,18 @@ int main(int argc, char *argv[], char *envp[]) case 'b': session->bash = 1; break; + case 'c': + if (session->configfile) + free(session->configfile); + session->configfile = strdup(optarg); + dbg("configfile = %s\n", session->configfile); + + /* + * read the config file now. Yes, this could override previously + * set options from the command line, but the user asked for it... + */ + parse_configfile(session); + break; case 'h': display_help(); goto exit; diff --git a/bti.xml b/bti.xml index 091f824..eb93b41 100644 --- a/bti.xml +++ b/bti.xml @@ -33,6 +33,7 @@ + @@ -128,6 +129,17 @@ + + + + + Specify a config file for bti to read from. By default, bti + looks in the ~/.bti file for config values. This default + location can be overridden by setting a specific file with this + option. + + + @@ -361,7 +373,10 @@ For example, command line options always override any config file - option, or any environment variables. + option, or any environment variables. Unless a config file is + specified by the command line. At that point, the new config file is + read, and any previous options set by a command line option, would be + overridden.