vimgolf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -1
- data/lib/vimgolf/cli.rb +24 -10
- data/lib/vimgolf/version.rb +1 -1
- data/spec/cli_spec.rb +16 -0
- data/vimgolf.gemspec +3 -2
- metadata +20 -5
data/Gemfile.lock
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vimgolf (0.0
|
4
|
+
vimgolf (0.1.0)
|
5
|
+
json
|
5
6
|
thor
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: http://rubygems.org/
|
9
10
|
specs:
|
10
11
|
diff-lcs (1.1.2)
|
12
|
+
json (1.4.6)
|
11
13
|
rspec (2.3.0)
|
12
14
|
rspec-core (~> 2.3.0)
|
13
15
|
rspec-expectations (~> 2.3.0)
|
@@ -22,6 +24,7 @@ PLATFORMS
|
|
22
24
|
ruby
|
23
25
|
|
24
26
|
DEPENDENCIES
|
27
|
+
json
|
25
28
|
rspec
|
26
29
|
thor
|
27
30
|
vimgolf!
|
data/lib/vimgolf/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module VimGolf
|
2
2
|
|
3
|
-
GOLFHOST =
|
3
|
+
GOLFHOST = ENV['GOLFHOST'] || "http://vimgolf.com"
|
4
|
+
GOLFDEBUG = ENV['GOLFDEBUG'].to_sym rescue false
|
4
5
|
|
5
6
|
class Error
|
6
7
|
end
|
@@ -38,7 +39,7 @@ module VimGolf
|
|
38
39
|
def setup
|
39
40
|
token = VimGolf.ui.ask "Please specify your VimGolf API token (register on vimgolf.com to get it):"
|
40
41
|
|
41
|
-
if token =~ /[\w\d]{
|
42
|
+
if token =~ /[\w\d]{32}/
|
42
43
|
FileUtils.mkdir_p Config.path
|
43
44
|
FileUtils.mkdir_p Config.put_path
|
44
45
|
Config.save({:key => token})
|
@@ -58,13 +59,15 @@ module VimGolf
|
|
58
59
|
def put(id = nil)
|
59
60
|
VimGolf.ui.warn "Launching VimGolf session for challenge: #{id}"
|
60
61
|
|
61
|
-
|
62
|
+
begin
|
63
|
+
type = download(id)
|
62
64
|
|
63
|
-
if !type.nil? && !type.empty?
|
64
65
|
# - n - no swap file, memory only editing
|
65
66
|
# - --noplugin - don't load any plugins, lets be fair!
|
67
|
+
# -u NONE and -U none - don't load .vimrc or .gvimrc
|
68
|
+
# -i NONE - don't load .viminfo (for saved macros and the like)
|
66
69
|
# - +0 - always start on line 0
|
67
|
-
system("vim -n --noplugin +0 -W #{log(id)} #{input(id, type)}")
|
70
|
+
system("vim -n --noplugin -i NONE +0 -W #{log(id)} #{input(id, type)}")
|
68
71
|
|
69
72
|
if $?.exitstatus.zero?
|
70
73
|
diff = `diff --strip-trailing-cr #{input(id, type)} #{output(id)}`
|
@@ -88,7 +91,7 @@ module VimGolf
|
|
88
91
|
VimGolf.ui.info "Uploaded entry, thanks for golfing!"
|
89
92
|
VimGolf.ui.info "View the leaderboard: #{GOLFHOST}/challenges/#{id}"
|
90
93
|
else
|
91
|
-
VimGolf.ui.error "Uh oh, upload
|
94
|
+
VimGolf.ui.error "Uh oh, upload filed. You're not cheating are you? :-)"
|
92
95
|
end
|
93
96
|
|
94
97
|
else
|
@@ -103,10 +106,14 @@ module VimGolf
|
|
103
106
|
|
104
107
|
VimGolf.ui.error error
|
105
108
|
end
|
109
|
+
|
110
|
+
rescue Exception => e
|
111
|
+
VimGolf.ui.error "Uh oh, something wen't wrong! Error: #{e}"
|
112
|
+
VimGolf.ui.error "If the error persists, please report it to github.com/igrigorik/vimgolf"
|
106
113
|
end
|
107
114
|
end
|
108
115
|
|
109
|
-
|
116
|
+
no_tasks do
|
110
117
|
def download(id)
|
111
118
|
begin
|
112
119
|
url = URI.parse("#{GOLFHOST}/challenges/#{id}.json")
|
@@ -126,8 +133,8 @@ module VimGolf
|
|
126
133
|
data['in']['type']
|
127
134
|
|
128
135
|
rescue Exception => e
|
129
|
-
|
130
|
-
|
136
|
+
debug(e)
|
137
|
+
raise "Uh oh, couldn't download or parse challenge, please verify your challenge id & client version."
|
131
138
|
end
|
132
139
|
end
|
133
140
|
|
@@ -146,10 +153,13 @@ module VimGolf
|
|
146
153
|
JSON.parse(res.body)['status'].to_sym
|
147
154
|
|
148
155
|
rescue Exception => e
|
149
|
-
|
156
|
+
debug(e)
|
157
|
+
raise "Uh oh, entry upload has failed, please check your key."
|
150
158
|
end
|
151
159
|
end
|
160
|
+
end
|
152
161
|
|
162
|
+
private
|
153
163
|
def input(id, type); challenge(id) + ".#{type}"; end
|
154
164
|
def output(id); challenge(id) + ".output"; end
|
155
165
|
def log(id); challenge(id) + ".log"; end
|
@@ -157,5 +167,9 @@ module VimGolf
|
|
157
167
|
def challenge(id)
|
158
168
|
Config.put_path + "/#{id}"
|
159
169
|
end
|
170
|
+
|
171
|
+
def debug(msg)
|
172
|
+
p [caller.first, msg] if GOLFDEBUG
|
173
|
+
end
|
160
174
|
end
|
161
175
|
end
|
data/lib/vimgolf/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -22,4 +22,20 @@ describe VimGolf do
|
|
22
22
|
out.should include("launch")
|
23
23
|
end
|
24
24
|
|
25
|
+
describe "download / upload challenge" do
|
26
|
+
let(:c) { VimGolf::CLI.new }
|
27
|
+
|
28
|
+
it "should raise error on invalid challenge" do
|
29
|
+
lambda { c.download('invalidID') }.should raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return type of challenge on success" do
|
33
|
+
c.download('4d1a1c36567bac34a9000002').should == "rb"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should raise error on invalid upload id" do
|
37
|
+
lambda { c.upload('invalidID') }.should raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
25
41
|
end
|
data/vimgolf.gemspec
CHANGED
@@ -13,8 +13,9 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = s.summary
|
14
14
|
|
15
15
|
s.rubyforge_project = "vimgolf"
|
16
|
-
s.add_dependency "thor"
|
16
|
+
s.add_dependency "thor", ">= 0.14.6"
|
17
17
|
s.add_dependency "json"
|
18
|
+
s.add_dependency "highline"
|
18
19
|
|
19
20
|
s.add_development_dependency "rspec"
|
20
21
|
|
@@ -22,4 +23,4 @@ Gem::Specification.new do |s|
|
|
22
23
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
25
|
s.require_paths = ["lib"]
|
25
|
-
end
|
26
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ilya Grigorik
|
@@ -27,7 +27,9 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 0
|
30
|
-
|
30
|
+
- 14
|
31
|
+
- 6
|
32
|
+
version: 0.14.6
|
31
33
|
type: :runtime
|
32
34
|
version_requirements: *id001
|
33
35
|
- !ruby/object:Gem::Dependency
|
@@ -44,7 +46,7 @@ dependencies:
|
|
44
46
|
type: :runtime
|
45
47
|
version_requirements: *id002
|
46
48
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
49
|
+
name: highline
|
48
50
|
prerelease: false
|
49
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
50
52
|
none: false
|
@@ -54,8 +56,21 @@ dependencies:
|
|
54
56
|
segments:
|
55
57
|
- 0
|
56
58
|
version: "0"
|
57
|
-
type: :
|
59
|
+
type: :runtime
|
58
60
|
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
59
74
|
description: CLI client for vimgolf.com
|
60
75
|
email:
|
61
76
|
- ilya@igvita.com
|