File tree 5 files changed +45
-56
lines changed
5 files changed +45
-56
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env ruby
2
2
require 'tryruby'
3
3
4
- TryRuby ::CLI . run
4
+ TryRuby ::CLI . new ( ARGV ) . run
5
5
6
6
# add -Ilib to run during development
Original file line number Diff line number Diff line change @@ -2,50 +2,18 @@ module TryRuby
2
2
class CLI
3
3
attr_accessor :options
4
4
5
- def initialize ( options = { } )
6
- self . options = options
5
+ def initialize ( args )
6
+ self . options = parse_options ( args )
7
7
end
8
8
9
- # def create_config_file
10
- # `open 'https://api.put.io/v2/oauth2/authenticate?client_id=183&response_type=code&redirect_uri=#{Getit::REDIRECT}'`
11
- # # stdin ask for code from the url
12
- # print "Please paste what comes after the 'code=': "
13
- # code = STDIN.gets
14
-
15
- # # request access_token with code
16
- # uri = URI.parse("https://api.put.io/v2/oauth2/access_token?client_id=#{Getit::ID}&client_secret=#{Getit::SECRET}&grant_type=authorization_code&redirect_uri=#{Getit::REDIRECT}&code=#{code}")
17
- # http = Net::HTTP.new(uri.host, uri.port)
18
- # http.use_ssl = true
19
- # http.verify_mode = OpenSSL::SSL::VERIFY_NONE
20
-
21
- # request = Net::HTTP::Get.new(uri.request_uri)
22
-
23
- # response = http.request(request)
24
-
25
- # new_access_token = ''
26
-
27
- # if response.code.to_i == 200
28
- # new_access_token = JSON.parse(response.body)['access_token']
29
- # end
30
-
31
- # # write file
32
- # @config = {
33
- # 'access_token' => 'access_token',
34
- # 'last_accessed_at' => Time.now.to_i
35
- # }
36
-
37
- # write_config_file
38
- # end
39
-
40
9
def run
41
10
TryRuby ::REPL . new ( options ) . start
42
11
end
43
12
44
- def self . run
45
- new ( parse_options ) . run
46
- end
13
+ private
47
14
48
- def self . parse_options
15
+ # @private
16
+ def parse_options ( args )
49
17
{ } . tap do |options |
50
18
51
19
OptionParser . new do |opts |
@@ -79,7 +47,7 @@ def self.parse_options
79
47
puts opts
80
48
exit
81
49
end
82
- end . parse!
50
+ end . parse! ( args )
83
51
84
52
end
85
53
end
Original file line number Diff line number Diff line change @@ -13,35 +13,34 @@ def start
13
13
display script . intro . formatted
14
14
15
15
while command = Readline . readline ( "> " , true )
16
- # print instructions if code == 'help'
17
-
18
16
case command
19
17
when "help"
20
18
display "Soon, I will have help for you."
21
19
when "next" , "continue"
22
20
display script . next . formatted
23
21
when "prev" , "previous" , "back"
24
22
display script . previous . formatted
25
- when "exit"
26
- display "Goodbye, I hope you had fun!\n "
27
- exit 0
23
+ when "exit" , "quit"
24
+ break
28
25
else
29
- begin
30
- result = eval ( command )
26
+ process ( command )
27
+ end
28
+ end
31
29
32
- display "=> #{ result } "
30
+ display "Goodbye, I hope you had fun!\n "
31
+ end
33
32
34
- display ( script . next . formatted ) if script . continue?
35
- rescue SyntaxError
36
- display "Oops, seems to have been some error. Care to try again?"
33
+ def process ( command )
34
+ begin
35
+ result = eval ( command )
37
36
38
- next
39
- rescue NameError
40
- display "Oops, you tried to use a method or variable that doesn't exist. Care to try again?"
37
+ display "=> #{ result } "
41
38
42
- next
43
- end
44
- end
39
+ display ( script . next . formatted ) if script . continue?
40
+ rescue SyntaxError
41
+ display "Oops, seems to have been some error. Care to try again?"
42
+ rescue NameError
43
+ display "Oops, you tried to use a method or variable that doesn't exist. Care to try again?"
45
44
end
46
45
end
47
46
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe TryRuby ::CLI do
4
+ context "a cli" do
5
+ let ( :cli ) { TryRuby ::CLI . new ( [ ] ) }
6
+
7
+ it 'runs the repl with parsed options' do
8
+ repl = stub ( :start )
9
+ TryRuby ::REPL . stubs ( :new ) . returns ( repl )
10
+
11
+ cli . run
12
+
13
+ expect ( repl ) . to have_received ( :start )
14
+ expect ( TryRuby ::REPL ) . to have_received ( :new ) . with ( { } )
15
+ end
16
+ end
17
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe TryRuby ::REPL do
4
+
5
+ end
You can’t perform that action at this time.
0 commit comments