forked from barbie/maisha
/
maisha
executable file
·335 lines (222 loc) · 8.35 KB
/
maisha
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/usr/bin/perl
use strict;
use warnings;
#----------------------------------------------------------------------------
# Library Modules
use File::HomeDir;
use FindBin;
use Getopt::Long;
use Pod::Usage;
use lib(File::Spec->catdir($FindBin::Bin, File::Spec->updir, 'lib'));
use App::Maisha;
#----------------------------------------------------------------------------
# Application
{
my ($config,%options);
# Default config file is expected to be in the user's home directory
$config = do {
my $home = File::HomeDir->my_home;
my $file;
foreach my $suffix qw(ini yml yaml) {
my $test = "$home/.maisha.$suffix";
if (-f $test) {
$file = $test;
last;
}
}
$file;
};
if (! GetOptions( \%options,
'config|c=s',
'version|v',
'usage|u',
'help|h'
)) {
usage(1);
}
usage(1) if($options{usage});
usage(0) if($options{version});
if ($options{help}) {
pod2usage(-verbose => 2);
exit(0);
}
$options{config} ||= $config;
usage(1,"No configuration file was specified and a default one could not be found")
unless( $options{config});
usage(1,"Configuration file [$options{config}] not found") unless(-f $options{config});
App::Maisha->new(config => $options{config})->run;
}
sub usage {
my ($full,$mess) = @_;
print "\n$mess\n" if($mess);
if($full) {
print "\n";
print "Usage: $0 [--config=<file>] [--help|h] [--usage|u] [--version|v] \n\n";
# 12345678901234567890123456789012345678901234567890123456789012345678901234567890
print "maisha - Micro-blogging from your command line.\n\n";
print "Options:\n";
print " [--config=<file>] # path to config file\n";
print " [--version] # program version\n";
print " [--usage] # basic usage help screen\n";
print " [--help] # displays the man page\n";
}
print "\n$0 v$App::Maisha::VERSION\n\n";
exit(0);
}
__END__
=head1 NAME
maisha - Micro-blogging From Your Command Line
=head1 SYNOPSIS
maisha
maisha -c mymaisha.ini
maisha -v
maisha -u
maisha -h
=head1 DESCRIPTION
maisha gives you access to micro-blogging from your command line
=head1 OPTIONS
=head2 --config | -c
Specify the config file to read from. By default, maisha attempts to read
a config file named config.ini in the current directory
=head2 --version | -v
Print out the version and exit
=head2 --usage | -u
Prints out a basic usage help screen
=head2 --help | -h
Print out the manual page.
=head1 CONFIGURATION
The configuration file must contain at least one micro-blogging service, with
your username and password for that service, all other configuration settings
are optional.
The configuration file itself can be in several different formats, XML, YAML,
JSON, Windows INI files and even pure Perl are all supported, provided you have
the correct distributions to support those file formats. As a guide the
following are known to work with this application:
Config::Tiny - INI file format
JSON - JSON file format
JSON::Syck - JSON file format
XML::Simple - XML file format
YAML - YAML file format
YAML::Syck - YAML file format
For further options for other file formats see L<Config::Tiny> for more
information. See also examples listed further below.
By default the INI and YAML file formats are used, with the application looking
for a default configuration file in your $HOME directory, named '.maisha.ini',
'.maisha.yml' or '.maisha.yaml'.
=head2 Application Configuration
The configuration for the application itself are contained within a 'CONFIG'
section in your configuration file. All settings are optional, and will default
to sensible values should they not be user defined.
=over 4
=item * prompt
The prompt you wish to see on the command line. This will default to 'maisha>'
if not configured.
=item * tag
The tag you wish to have added to the end of an update/say command. This will
default to '[from maisha]' if not configured. If you do not wish a tag to
be added at all, set the tag to '.' in the configuration file.
=item * order
Describes the order for printing status messages when a timeline command is
requested. Will default to 'descending' if not configured. Setting is case
insensitive and should be set to 'ascending' or 'asc' to reverse the order.
=item * limit
Describes how many status messages should be printed when a timeline command is
requested. Will default to the last 20 if not configured.
=item * pager
Enables the use of a pager when viewing timelines. Defaults to true
if not specified.
=item * format
When printing a list of status messages, the default format of printing the
username followed by the status message is not always suitable for everyone. As
such you can define your own formatting.
The default format is "[%U] %M", with the available formatting patterns defined
as:
%U - username or screen name
%M - status message
%T - timestamp
%N - network
=item * chars
As Maisha is run from the command line, it is most likely being run within a
terminal window. Unfortunately there isn't currently a detection method for
knowing the exact screen width being used. As such you can specify a width for
the wrapper to use to ensure the messages are correctly line wrapped. The
default setting is 80.
=back
=head2 Service Configuration
For each service you have available (the default install includes 'Identica'
and 'Twitter') include an associated section in your configuration file,
providing a username and password for that service. If any service fails to
connect, a warning is emitted. If the application is not able to connect to
any service, the application will terminate with an error message.
=over 4
=item * username
Your username login to your network service account
=item * password
Your password login to your network service account
=back
=head1 COMMANDS
Note that not all services offer all commands. Where commands are not
applicable for a service, and appropriate warning message will be emitted.
=over 4
=item * friends
Displays the most recent status messages from each of your friends.
=item * friends_timeline | ft [<limit>]
Displays the most recent status messages within your friends timeline.
=item * public_timeline | pt [<limit>]
Displays the most recent status messages within the public timeline.
=item * followers
Displays the most recent status messages from each of your followers.
=item * replies | re [<limit>]
Displays the most recent reply messages.
=item * direct_messages | dm [<limit>]
Displays the most recent direct messages you have received.
=item * send_message | send | sm <user> <message>
Post a direct message to another user. Include the username of the person you
wish to send a message to, followed by your message, of upto 140 characters in
length.
=item * update | say <message>
Posts a new status message, of upto 140 characters in length.
=item * exit | quit | q
Exits the program.
=item * help
Provides help for a specific command, or provides a summary of the commands
available if requested with no arguments.
=back
=head2 Example Configuration Files
=head3 INI Style Configuration
Requires Config::Tiny to be available.
[CONFIG]
order: asc
tag: .
[Identica]
username: yourlogin
password: yourpassword
[Twitter]
username: yourlogin
password: yourpassword
=head3 YAML Style Configuration
Requires YAML or YAML::Syck to be available.
--- #YAML:1.0
CONFIG:
order: asc
tag: .
Twitter:
username: yourlogin
password: yourpassword
Identica:
username: yourlogin
password: yourpassword
=head3 Perl Style Configuration
No additional dependencies required.
{
CONFIG => {'order': 'asc','tag': '.'},
Twitter => {'username': 'yourlogin','password': 'yourpassword'},
Identica => {'username': 'yourlogin','password': 'yourpassword'},
}
=head1 AUTHOR
Copyright (c) 2009 Barbie <barbie@cpan.org> Miss Barbell Productions.
=head1 LICENSE
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
=cut