twat 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/TODO +13 -0
- data/doc/twat.1 +19 -1
- data/lib/twat.rb +9 -2
- data/lib/twat/actions.rb +23 -12
- data/lib/twat/argparse.rb +5 -3
- data/lib/twat/config.rb +5 -0
- data/lib/twat/exceptions.rb +3 -0
- data/lib/twat/migration.rb +13 -1
- data/lib/twat/options.rb +50 -0
- metadata +7 -6
data/TODO
CHANGED
@@ -18,3 +18,16 @@ COLORS!
|
|
18
18
|
twat -l should dump colors to terminal (This should be configurable tho)
|
19
19
|
|
20
20
|
Refactor tweet printing code, unify throughout
|
21
|
+
|
22
|
+
MIGRATIONS
|
23
|
+
==========
|
24
|
+
|
25
|
+
Shouldn't run if config is up to date
|
26
|
+
|
27
|
+
TODO
|
28
|
+
====
|
29
|
+
|
30
|
+
Finish the config stuff (change --set-default <acct> to --set
|
31
|
+
DEFAULT=<acct>)
|
32
|
+
implement twat -f that just ticks by (have some option to ring a bell or
|
33
|
+
some shit)
|
data/doc/twat.1
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
.SH NAME
|
3
3
|
twat \- a cli/ruby interface to twitter.
|
4
4
|
.SH SYNOPSIS
|
5
|
-
.B twat [-n account] <-a|-d
|
5
|
+
.B twat [-n account] <-a|-d|-l|-u [user]>
|
6
|
+
.B twat [-n account] tweet goes here
|
6
7
|
.SH DESCRIPTION
|
7
8
|
.B twat
|
8
9
|
gives a simple interface to twitter from the command line.
|
@@ -19,6 +20,23 @@ Tell twat to execute the routines for authenticating itself with OAuth for your
|
|
19
20
|
account.
|
20
21
|
.IP -d
|
21
22
|
Delete speficied account.
|
23
|
+
.IP -h
|
24
|
+
Display a short summary of twat's options.
|
25
|
+
.IP -u USER
|
26
|
+
Retrieve a list of USER's recent tweets. Note this will retrieve all of their
|
27
|
+
tweets as opposed to just what would have appeared in your feed.
|
28
|
+
.SH CONFIGURATION
|
29
|
+
Options are configured with --set OPTION=VALUE.
|
30
|
+
Options include
|
31
|
+
.IP default=account
|
32
|
+
Sets account as the default
|
33
|
+
.IP colors=<true|false>
|
34
|
+
Turns colors on or off in the output from twat.
|
35
|
+
.IP --update-config
|
36
|
+
Twat is a rolling release and as such, sometimes it is necessary to change the
|
37
|
+
format of it's internal config file. Rather than making changes without user
|
38
|
+
consent, twat instead allows a user to use --update-config to migrate their
|
39
|
+
config to the latest version.
|
22
40
|
.SH FILES
|
23
41
|
.IP ~/.twatrc
|
24
42
|
yaml file containing a mapping of account nicknames to oauth credentials.
|
data/lib/twat.rb
CHANGED
@@ -6,7 +6,7 @@ require 'yaml'
|
|
6
6
|
require 'optparse'
|
7
7
|
require 'oauth'
|
8
8
|
|
9
|
-
%w[config exceptions argparse actions migration].each do |filename|
|
9
|
+
%w[config exceptions argparse actions migration options].each do |filename|
|
10
10
|
require "twat/#{filename}"
|
11
11
|
end
|
12
12
|
|
@@ -39,7 +39,7 @@ end
|
|
39
39
|
module Twat
|
40
40
|
VERSION_MAJOR = 0
|
41
41
|
VERSION_MINOR = 4
|
42
|
-
VERSION_PATCH =
|
42
|
+
VERSION_PATCH = 2
|
43
43
|
|
44
44
|
VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
|
45
45
|
class Twat
|
@@ -63,11 +63,18 @@ module Twat
|
|
63
63
|
rescue NoConfigFile
|
64
64
|
puts "No config file, create one with twat -a [user|nick]"
|
65
65
|
opts.usage
|
66
|
+
rescue InvalidSetOpt
|
67
|
+
puts "There is no such configurable option"
|
68
|
+
opts.usage
|
69
|
+
rescue RequiresOptVal
|
70
|
+
puts "--set must take an option=value pair as arguments"
|
66
71
|
rescue InvalidCredentials
|
67
72
|
puts "Invalid credentials, try reauthenticating with"
|
68
73
|
puts "twat -a #{opts[:account]}"
|
69
74
|
rescue ConfigVersionIncorrect
|
70
75
|
puts "Your config file is out of date. Run with --update-config to rememdy"
|
76
|
+
rescue InvalidBool
|
77
|
+
puts "Invalid value, valid values are #{Options::BOOL_VALID.join("|")}"
|
71
78
|
end
|
72
79
|
end
|
73
80
|
end
|
data/lib/twat/actions.rb
CHANGED
@@ -44,14 +44,13 @@ module Twat
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
def setoption
|
48
|
+
k, v = opts[:optval].split("=")
|
49
|
+
raise RequiresOptVal unless v
|
50
|
+
options = Options.new
|
51
|
+
options.send(:"#{k}=", v)
|
51
52
|
|
52
|
-
|
53
|
-
config.save!
|
54
|
-
puts "Successfully set #{opts[:account]} as default"
|
53
|
+
puts "Successfully set #{k} as #{v}"
|
55
54
|
end
|
56
55
|
|
57
56
|
def updateconfig
|
@@ -83,7 +82,7 @@ module Twat
|
|
83
82
|
puts "twat: #{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
|
84
83
|
end
|
85
84
|
|
86
|
-
def method_missing
|
85
|
+
def method_missing(sym, *args, &block)
|
87
86
|
raise NoSuchCommand
|
88
87
|
end
|
89
88
|
|
@@ -91,11 +90,14 @@ module Twat
|
|
91
90
|
|
92
91
|
# Format a tweet all pretty like
|
93
92
|
def format(twt)
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
if config.colors?
|
94
|
+
if twt.user.screen_name == account_name.to_s
|
95
|
+
puts "#{twt.user.screen_name.bold.blue}: #{twt.text}"
|
96
|
+
else
|
97
|
+
puts "#{twt.user.screen_name.bold.cyan}: #{twt.text}"
|
98
|
+
end
|
97
99
|
else
|
98
|
-
puts "#{twt.user.screen_name
|
100
|
+
puts "#{twt.user.screen_name}: #{twt.text}"
|
99
101
|
end
|
100
102
|
end
|
101
103
|
|
@@ -110,6 +112,15 @@ module Twat
|
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
115
|
+
def account_name
|
116
|
+
@account_name ||=
|
117
|
+
if opts.include?(:account)
|
118
|
+
opts[:account]
|
119
|
+
else
|
120
|
+
config[:default]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
113
124
|
def account
|
114
125
|
@account = config.accounts[account_name]
|
115
126
|
end
|
data/lib/twat/argparse.rb
CHANGED
@@ -4,6 +4,8 @@ module Twat
|
|
4
4
|
|
5
5
|
class ArgParse
|
6
6
|
|
7
|
+
# TODO delegate specifically instead of shimming everything?
|
8
|
+
|
7
9
|
def usage(additional=nil)
|
8
10
|
puts additional if additional
|
9
11
|
puts @optparser
|
@@ -42,9 +44,9 @@ module Twat
|
|
42
44
|
options[:user] = (user || :default)
|
43
45
|
options[:action] = :user_feed
|
44
46
|
end #}}}
|
45
|
-
opts.on("--set
|
46
|
-
options[:action] = :
|
47
|
-
options[:
|
47
|
+
opts.on("--set OPTION=VALUE", 'Set OPTION to VALUE') do |optval| #{{{ --set OPTION=VALUE
|
48
|
+
options[:action] = :setoption
|
49
|
+
options[:optval] = optval
|
48
50
|
end #}}}
|
49
51
|
opts.on("--update-config", "Update config to latest version") do #{{{ --update-config
|
50
52
|
options[:action] = :updateconfig
|
data/lib/twat/config.rb
CHANGED
@@ -48,6 +48,11 @@ module Twat
|
|
48
48
|
return config[:accounts]
|
49
49
|
end
|
50
50
|
|
51
|
+
def colors?
|
52
|
+
colors = config[:colors] || "true"
|
53
|
+
Options.bool_true?(colors)
|
54
|
+
end
|
55
|
+
|
51
56
|
def default_account
|
52
57
|
raise NoDefaultAccount unless config.include?(:default)
|
53
58
|
return config[:default].to_sym
|
data/lib/twat/exceptions.rb
CHANGED
@@ -3,7 +3,10 @@ module Twat
|
|
3
3
|
class NoDefaultAccount < Exception; end
|
4
4
|
class NoSuchCommand < Exception; end
|
5
5
|
class NoConfigFile < Exception; end
|
6
|
+
class RequiresOptVal < Exception; end
|
6
7
|
class Usage < Exception; end
|
7
8
|
class InvalidCredentials < Exception; end
|
8
9
|
class ConfigVersionIncorrect < Exception; end
|
10
|
+
class InvalidSetOpt < Exception; end
|
11
|
+
class InvalidBool < Exception; end
|
9
12
|
end
|
data/lib/twat/migration.rb
CHANGED
@@ -2,7 +2,18 @@ module Twat
|
|
2
2
|
class Migrate
|
3
3
|
def migrate!(filename)
|
4
4
|
@file = filename
|
5
|
-
|
5
|
+
@ran = []
|
6
|
+
migration_1 if migration_1?
|
7
|
+
if @ran.any?
|
8
|
+
puts "Successfully ran migrations: #{@ran.join(", ")}"
|
9
|
+
else
|
10
|
+
puts "Already up to date"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def migration_1?
|
15
|
+
current = YAML.load_file(@file)
|
16
|
+
return !current.include?(:accounts)
|
6
17
|
end
|
7
18
|
|
8
19
|
def migration_1
|
@@ -26,6 +37,7 @@ module Twat
|
|
26
37
|
end
|
27
38
|
|
28
39
|
save(new)
|
40
|
+
@ran << "1"
|
29
41
|
end
|
30
42
|
|
31
43
|
def save(cf)
|
data/lib/twat/options.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Twat
|
2
|
+
class Options
|
3
|
+
BOOL_TRUE=["yes", "true", "1", "on"]
|
4
|
+
BOOL_FALSE=["no", "false", "0", "off"]
|
5
|
+
BOOL_VALS = BOOL_TRUE + BOOL_FALSE
|
6
|
+
def self.bool_true?(val)
|
7
|
+
BOOL_TRUE.include?(val.to_s.downcase)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.bool_false?(val)
|
11
|
+
BOOL_FALSE.include?(val.to_s.downcase)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.bool_valid?(val)
|
15
|
+
BOOL_VALS.include?(val.to_s.downcase)
|
16
|
+
end
|
17
|
+
|
18
|
+
# A set of wrappers around the global config object to set given attributes
|
19
|
+
# Catching failures is convenient because of the method_missing? hook
|
20
|
+
def method_missing(sym, *args, &block)
|
21
|
+
puts sym
|
22
|
+
raise InvalidSetOpt
|
23
|
+
end
|
24
|
+
|
25
|
+
def config
|
26
|
+
@config ||= Config.new
|
27
|
+
end
|
28
|
+
|
29
|
+
# This is deliberately not abstracted (it could be easily accessed from
|
30
|
+
# withing the method_missing method, but that will just lead to nastiness
|
31
|
+
# later when I implement colors, for example.
|
32
|
+
def default=(value)
|
33
|
+
val = value.to_sym
|
34
|
+
unless config.accounts.include?(val)
|
35
|
+
raise NoSuchAccount
|
36
|
+
end
|
37
|
+
|
38
|
+
config[:default] = val
|
39
|
+
config.save!
|
40
|
+
end
|
41
|
+
|
42
|
+
def colors=(value)
|
43
|
+
val = value.to_sym
|
44
|
+
raise InvalidBool unless Options.bool_valid?(val)
|
45
|
+
config[:colors] = val
|
46
|
+
config.save!
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: twitter
|
16
|
-
requirement: &
|
16
|
+
requirement: &20971900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *20971900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: oauth
|
27
|
-
requirement: &
|
27
|
+
requirement: &20971320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *20971320
|
36
36
|
description: Command line tool for tweeting and whatnot
|
37
37
|
email:
|
38
38
|
- richo@psych0tik.net
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/twat/config.rb
|
55
55
|
- lib/twat/exceptions.rb
|
56
56
|
- lib/twat/migration.rb
|
57
|
+
- lib/twat/options.rb
|
57
58
|
- twat.gemspec
|
58
59
|
homepage: http://github.com/richoH/twat
|
59
60
|
licenses: []
|