lib/cli.rb in exercism-0.0.25 vs lib/cli.rb in exercism-0.0.26
- old
+ new
@@ -35,10 +35,17 @@
assignments = api.fetch
report(assignments)
end
+ desc "open", "Opens exercism.io in your default browser"
+ def open
+ require 'launchy'
+
+ Launchy.open("http://exercism.io")
+ end
+
desc "peek", "Fetch upcoming assignment from exercism.io"
method_option :host, :aliases => '-h', :default => 'http://exercism.io', :desc => 'the url of the exercism application'
def peek
require 'exercism'
@@ -49,10 +56,11 @@
desc "submit FILE", "Submit code to exercism.io on your current assignment"
method_option :host, :aliases => '-h', :default => 'http://exercism.io', :desc => 'the url of the exercism application'
method_option :ask, :aliases => '-a', :default => false, :type => :boolean, :desc => 'ask before submitting assignment'
def submit(file)
require 'exercism'
+ require 'cli/monitored_request'
submission = Submission.new(file)
if submission.test?
say "It looks like this is a test, you probably don't want to do that."
@@ -65,24 +73,27 @@
if no?("Are you sure you want to submit this assignment? [y/n]")
return
end
end
- begin
- response = Exercism::Api.new(options[:host], Exercism.user).submit(submission.path)
+ MonitoredRequest.new(api).request :submit, submission.path do |request, body|
+ say "Your assignment has been submitted."
+ url = "#{options[:host]}/#{Exercism.user.github_username}/#{body['language']}/#{body['exercise']}"
+ say "For feedback on your submission visit #{url}"
+ end
+ end
- body = JSON.parse(response.body)
- if body["error"]
- say body["error"]
- else
- say "Your assignment has been submitted."
- url = "#{options[:host]}/#{Exercism.user.github_username}/#{body['language']}/#{body['exercise']}"
- say "For feedback on your submission visit #{url}"
+ desc "unsubmit", "Delete the last submission"
+ method_option :host, :aliases => '-h', :default => 'http://exercism.io', :desc => 'the url of the exercism application'
+ def unsubmit
+ require 'exercism'
+ require 'cli/monitored_request'
+
+ MonitoredRequest.new(api).request :unsubmit do |request, body|
+ if response.status == 204
+ say "The last submission was successfully deleted."
end
- rescue Exception => e
- puts "There was an issue with your submission."
- puts e.message
end
end
desc "login", "Save exercism.io api credentials"
def login
@@ -117,10 +128,11 @@
def key
ask("Your exercism.io API key:")
end
+
def project_dir
default_dir = FileUtils.pwd
say "What is your exercism exercises project path?"
say "Press Enter to select the default (#{default_dir}):\n"
dir = ask ">", :default => default_dir
@@ -140,8 +152,7 @@
say File.join(assignment.exercise, 'README.md')
say File.join(assignment.exercise, assignment.test_file)
end
end
end
-
end
end