bropages 0.0.15 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/bro +1 -2
- data/lib/bro.rb +42 -18
- data/lib/bro/bro_state.rb +42 -26
- data/lib/bro/string_hacks.rb +55 -17
- data/lib/bro/version.rb +1 -1
- metadata +30 -16
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzMwOWM3M2MzNDBhOTI1MWJjOThiN2IxOTczZDZmMGY3ZmIwYTYzNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWVmMjhmNjMwMGFiNWM2ODk0ZjI4NGJkMzBiNDg3NTk3YzVmYjlmMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzY5MDYwNzAyY2E0MzA5NDQ4ODhhMTIwZmJmMDYyMmI2ZDJiZWM5MTFmYjJh
|
10
|
+
YTQwMDMzYThhODZjM2NlMzUyODAxOGJkNjc1Zjk2MTBlNjMyZThiNDgzMDkx
|
11
|
+
MDk3ZjVkMjNjYzI2Nzg3MzJlMjdhMWQ4MTRkMThlYmQ0OGFkZjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTk3NWQ1ZGQzNmI1NDUwNzlmMTk5Y2ZlZDczMWNjZTEwZmNhNWUzMjEwNGM1
|
14
|
+
MDc5Njc0ZWY1Y2E5OTAwNGI2NGZjY2I1Y2RhMDQ4MDAwZTRjZjRmNWRmN2Vm
|
15
|
+
NjU2MGZkMGY1YTUwZWExNjNiZmMyZmNkNGJmMjQzZWYwZTVkOTc=
|
data/bin/bro
CHANGED
data/lib/bro.rb
CHANGED
@@ -1,20 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# 1.8.7 support
|
4
|
+
unless Kernel.respond_to?(:require_relative)
|
5
|
+
module Kernel
|
6
|
+
def require_relative(path)
|
7
|
+
require File.join(File.dirname(caller[0]), path.to_str)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
2
12
|
require 'rubygems'
|
3
13
|
require 'json'
|
4
14
|
require 'commander/import'
|
5
15
|
require 'highline'
|
6
|
-
require 'smart_colored'
|
7
16
|
require 'rest-client'
|
8
17
|
|
9
|
-
$LOAD_PATH << "."
|
10
18
|
require_relative 'bro/state.rb'
|
11
19
|
require_relative 'bro/bro_state.rb'
|
12
20
|
require_relative 'bro/string_hacks.rb'
|
13
21
|
require_relative 'bro/version.rb'
|
14
|
-
include Bro
|
15
22
|
|
16
23
|
URL = ENV["BROPAGES_URL"] || 'http://bropages.org'
|
17
24
|
FILE = ENV["HOME"] + '/.bro'
|
25
|
+
RestClient.proxy = ENV['http_proxy']
|
18
26
|
|
19
27
|
program :name, 'bro'
|
20
28
|
program :version, Bro::VERSION
|
@@ -23,6 +31,12 @@ default_command :lookup
|
|
23
31
|
|
24
32
|
state = Bro::BroState.new({:file => FILE})
|
25
33
|
|
34
|
+
if state.check_color
|
35
|
+
ColoredText.apply
|
36
|
+
else
|
37
|
+
VanillaText.apply
|
38
|
+
end
|
39
|
+
|
26
40
|
command :thanks do |c|
|
27
41
|
c.syntax = 'bro thanks [COMMAND]'
|
28
42
|
c.summary = 'Upvote an entry, bro'
|
@@ -31,9 +45,8 @@ command :thanks do |c|
|
|
31
45
|
c.action do |args, options|
|
32
46
|
begin
|
33
47
|
login_details = state.check_email
|
34
|
-
rescue
|
48
|
+
rescue Interrupt, StandardError
|
35
49
|
say "Sorry, you can't do this without email verification".sorry
|
36
|
-
say "#{e}"
|
37
50
|
end
|
38
51
|
unless login_details.nil?
|
39
52
|
cmd = state.read_state[:cmd]
|
@@ -50,12 +63,12 @@ command :thanks do |c|
|
|
50
63
|
id = state.read_state[idkey.intern]
|
51
64
|
|
52
65
|
if id.nil?
|
53
|
-
say "That
|
66
|
+
say "That index (#{idkey}) does not exist for #{cmd}, try another one".sorry
|
54
67
|
end
|
55
68
|
|
56
69
|
unless id.nil?
|
57
70
|
begin
|
58
|
-
|
71
|
+
RestClient.get URL + "/thanks/#{id}", { :params => login_details }
|
59
72
|
rescue => e
|
60
73
|
say e.message
|
61
74
|
say "There was a problem thanking the #{cmd} entry. This entry may not exist or bropages.org may be down".problem
|
@@ -76,9 +89,8 @@ noblock = lambda { |c|
|
|
76
89
|
c.action do |args, options|
|
77
90
|
begin
|
78
91
|
login_details = state.check_email
|
79
|
-
rescue
|
92
|
+
rescue Interrupt, StandardError
|
80
93
|
say "Sorry, you can't do this without email verification".sorry
|
81
|
-
say "#{e}"
|
82
94
|
end
|
83
95
|
unless login_details.nil?
|
84
96
|
|
@@ -101,7 +113,7 @@ noblock = lambda { |c|
|
|
101
113
|
|
102
114
|
unless id.nil?
|
103
115
|
begin
|
104
|
-
|
116
|
+
RestClient.get URL + "/no/#{id}", { :params => login_details }
|
105
117
|
rescue => e
|
106
118
|
say "There was a problem downvoting the #{cmd} entry. This entry may not exist or bropages.org may be down".problem
|
107
119
|
say e
|
@@ -131,9 +143,8 @@ command :add do |c|
|
|
131
143
|
c.action do |args, options|
|
132
144
|
begin
|
133
145
|
login_details = state.check_email
|
134
|
-
rescue
|
146
|
+
rescue Interrupt, StandardError
|
135
147
|
say "Sorry, you can't do this without email verification".sorry
|
136
|
-
say e
|
137
148
|
end
|
138
149
|
|
139
150
|
unless login_details.nil?
|
@@ -156,12 +167,12 @@ command :add do |c|
|
|
156
167
|
# your_comment_here
|
157
168
|
your_command_here
|
158
169
|
QQQ
|
159
|
-
entry = ask_editor prompt
|
160
|
-
if entry.gsub(prompt, '').strip.length > 0
|
161
|
-
if agree
|
170
|
+
entry = ask_editor prompt
|
171
|
+
if !entry.nil? && entry.gsub(prompt, '').strip.length > 0
|
172
|
+
if agree("Submit this entry for #{cmd}? [y/n] ") { |q| q.default = "yes" }
|
162
173
|
say "All right, sending your entry...".status
|
163
174
|
begin
|
164
|
-
|
175
|
+
RestClient.post URL + '/', login_details.merge({ :entry => { :cmd => cmd, :msg => entry}, :format => 'json', :multipart => true })
|
165
176
|
rescue => e
|
166
177
|
say e.message
|
167
178
|
file = "/tmp/#{cmd}.bro"
|
@@ -195,7 +206,20 @@ command :lookup do |c|
|
|
195
206
|
c.summary = 'Lookup an entry, bro. Or just call bro [COMMAND]'
|
196
207
|
c.description = "This looks up entries in the http://bropages.org database."
|
197
208
|
c.example 'Look up the bro entries for curl', 'bro curl'
|
209
|
+
c.option '--no-color', 'Switch colored output OFF'
|
210
|
+
c.option '--with-color', 'Switch colored output ON'
|
198
211
|
c.action do |args, options|
|
212
|
+
unless options.no_color.nil?
|
213
|
+
# set no-color as default
|
214
|
+
state.write_state({ :color => Bro::BroState::COLOR_OFF })
|
215
|
+
VanillaText.apply
|
216
|
+
end
|
217
|
+
unless options.with_color.nil?
|
218
|
+
# set color as default
|
219
|
+
state.write_state({ :color => "" })
|
220
|
+
ColoredText.apply
|
221
|
+
end
|
222
|
+
|
199
223
|
if args.empty?
|
200
224
|
say <<-QQQ.unindent
|
201
225
|
#{"Bro! Specify a command first!".colored.red}
|
@@ -215,13 +239,13 @@ command :lookup do |c|
|
|
215
239
|
state.reset_lookup_ids()
|
216
240
|
|
217
241
|
# write to ~/.bro file with last command
|
218
|
-
state.write_state({ cmd
|
242
|
+
state.write_state({ :cmd => cmd_display })
|
219
243
|
|
220
244
|
# connect to webservice for entry
|
221
245
|
error = false
|
222
246
|
begin
|
223
247
|
res = RestClient.get URL + '/' + cmd + '.json'
|
224
|
-
rescue
|
248
|
+
rescue
|
225
249
|
say <<-QQQ.unindent
|
226
250
|
The #{cmd_display.colored.yellow} command isn't in our database.
|
227
251
|
|
data/lib/bro/bro_state.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
module Bro
|
2
2
|
class BroState < State
|
3
|
+
COLOR_OFF = "nocolor"
|
4
|
+
|
5
|
+
# true/false if color should be used
|
6
|
+
def check_color
|
7
|
+
state = read_state
|
8
|
+
return state[:color] != COLOR_OFF
|
9
|
+
end
|
10
|
+
|
3
11
|
def get_arg_or_last_command args
|
4
12
|
cmd = args.join(" ")
|
5
13
|
if args.empty?
|
6
14
|
state = read_state
|
7
|
-
cmd = state[:cmd]
|
15
|
+
cmd = state[:cmd]
|
16
|
+
return nil if state.nil? or cmd.nil?
|
17
|
+
cmd.strip!
|
8
18
|
end
|
9
19
|
cmd
|
10
20
|
end
|
11
21
|
|
12
22
|
def reset_lookup_ids
|
13
23
|
# drop all lookup ids
|
14
|
-
|
24
|
+
new_state = read_state().delete_if { |k, v| !!(k =~ /\d+/) }
|
25
|
+
write_state(new_state, true)
|
15
26
|
end
|
16
27
|
|
17
28
|
def check_email
|
@@ -20,7 +31,7 @@ module Bro
|
|
20
31
|
rescue => e
|
21
32
|
prompt_email
|
22
33
|
end
|
23
|
-
{code
|
34
|
+
{ :code => read_state[:code], :email => read_state[:email]}
|
24
35
|
end
|
25
36
|
|
26
37
|
def prompt_email
|
@@ -28,36 +39,41 @@ module Bro
|
|
28
39
|
|
29
40
|
email = ""
|
30
41
|
|
31
|
-
while is_invalid_email email
|
32
|
-
email = ask "What's your email address?".colored.green
|
33
|
-
end
|
34
|
-
|
35
42
|
begin
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
raise e
|
40
|
-
else
|
41
|
-
say "Great! We're sending an email to #{email}".success
|
42
|
-
|
43
|
-
invalid_code = true
|
43
|
+
while is_invalid_email email
|
44
|
+
email = ask "What's your email address?".colored.green
|
45
|
+
end
|
44
46
|
begin
|
45
|
-
|
47
|
+
email_param = CGI.escape(email)
|
48
|
+
res = RestClient.post URL + '/users.json', { :user => { :email => email_param }, :format => 'json', :multipart => true }
|
49
|
+
rescue => e
|
50
|
+
say "There was an error delivering to your email address. Please try again later".colored.yellow.on_red
|
51
|
+
raise e
|
52
|
+
else
|
53
|
+
say "Great! We're sending an email to #{email}".success
|
54
|
+
|
55
|
+
invalid_code = true
|
46
56
|
begin
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
57
|
+
code = ask "Please enter the verification code: "
|
58
|
+
begin
|
59
|
+
is_invalid_code code, email
|
60
|
+
invalid_code = false
|
61
|
+
say "Great! You're verified! FYI, your email and code are stored locally in ~/.bro".success
|
62
|
+
write_state({ :email => email, :code => code })
|
63
|
+
rescue => e
|
64
|
+
say "Woops, there was a problem verifying your email. Please try again".colored.yellow.on_red
|
65
|
+
end
|
66
|
+
end while invalid_code
|
67
|
+
end
|
68
|
+
rescue Interrupt
|
69
|
+
say "Canceled email verification".status
|
70
|
+
raise
|
55
71
|
end
|
56
|
-
|
57
72
|
end
|
58
73
|
|
59
74
|
def is_invalid_code code, email
|
60
|
-
|
75
|
+
email_param = CGI.escape(email)
|
76
|
+
res = RestClient.get URL + "/users/verify?code=#{code}&email=#{email_param}"
|
61
77
|
end
|
62
78
|
|
63
79
|
def is_invalid_email email
|
data/lib/bro/string_hacks.rb
CHANGED
@@ -1,25 +1,63 @@
|
|
1
|
-
class
|
2
|
-
def
|
3
|
-
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
|
4
|
-
end
|
1
|
+
class FakeColor
|
2
|
+
def initialize(text); @text = text; end
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
%w{ red green yellow blue underline }.each do |m|
|
5
|
+
define_method(m){ @text }
|
8
6
|
end
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
class VanillaText
|
10
|
+
class << self
|
11
|
+
def apply
|
12
|
+
String.class_eval do
|
13
|
+
def colored
|
14
|
+
FakeColor.new self
|
15
|
+
end
|
16
|
+
|
17
|
+
def unindent
|
18
|
+
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
|
19
|
+
end
|
20
|
+
end
|
13
21
|
|
14
|
-
|
15
|
-
|
22
|
+
%w{ status success problem sorry important underline }.each do |m|
|
23
|
+
String.class_eval do
|
24
|
+
define_method(m){ self }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
16
28
|
end
|
29
|
+
end
|
17
30
|
|
18
|
-
|
19
|
-
|
20
|
-
|
31
|
+
class ColoredText
|
32
|
+
class << self
|
33
|
+
def apply
|
34
|
+
String.class_eval do
|
35
|
+
require 'smart_colored'
|
36
|
+
|
37
|
+
def unindent
|
38
|
+
gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
|
39
|
+
end
|
40
|
+
|
41
|
+
def status
|
42
|
+
self.colored.yellow
|
43
|
+
end
|
44
|
+
|
45
|
+
def success
|
46
|
+
self.colored.green.bold
|
47
|
+
end
|
48
|
+
|
49
|
+
def problem
|
50
|
+
self.colored.yellow_on_red_bold
|
51
|
+
end
|
52
|
+
|
53
|
+
def sorry
|
54
|
+
self.colored.red.bold
|
55
|
+
end
|
21
56
|
|
22
|
-
|
23
|
-
|
57
|
+
def important
|
58
|
+
self.colored.magenta
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
24
62
|
end
|
25
|
-
end
|
63
|
+
end
|
data/lib/bro/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bropages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bropages.org
|
@@ -14,30 +14,30 @@ dependencies:
|
|
14
14
|
name: json_pure
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.8.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.8.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: commander
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 4.1.5
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 4.1.5
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rest-client
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +70,30 @@ dependencies:
|
|
70
70
|
name: highline
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.6.20
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.6.20
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mime-types
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.19.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.19.0
|
83
97
|
description: Highly readable supplement to man pages. Shows simple, concise examples
|
84
98
|
for unix commands.
|
85
99
|
email: info@bropages.org
|
@@ -88,12 +102,12 @@ executables:
|
|
88
102
|
extensions: []
|
89
103
|
extra_rdoc_files: []
|
90
104
|
files:
|
91
|
-
- bin/bro
|
92
105
|
- lib/bro.rb
|
93
|
-
- lib/bro/bro_state.rb
|
94
106
|
- lib/bro/state.rb
|
107
|
+
- lib/bro/bro_state.rb
|
95
108
|
- lib/bro/string_hacks.rb
|
96
109
|
- lib/bro/version.rb
|
110
|
+
- bin/bro
|
97
111
|
homepage: http://bropages.org
|
98
112
|
licenses: []
|
99
113
|
metadata: {}
|
@@ -113,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
127
|
version: '0'
|
114
128
|
requirements: []
|
115
129
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.1.11
|
117
131
|
signing_key:
|
118
132
|
specification_version: 4
|
119
133
|
summary: Bro
|