Class: Clicoder::CLI
- Inherits:
-
Thor
- Object
- Thor
- Clicoder::CLI
- Defined in:
- lib/clicoder/cli.rb
Instance Method Summary collapse
- #add_test ⇒ Object
- #all ⇒ Object
- #browse ⇒ Object
- #build ⇒ Object
- #download ⇒ Object
- #execute ⇒ Object
- #judge ⇒ Object
- #submit ⇒ Object
Instance Method Details
#add_test ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/clicoder/cli.rb', line 113 def add_test load_local_config test_count = Dir.glob("#{INPUTS_DIRNAME}/*.txt").count input_file = "#{INPUTS_DIRNAME}/#{test_count}.txt" output_file = "#{OUTPUTS_DIRNAME}/#{test_count}.txt" puts 'Input:' system("cat > #{input_file}") puts 'Output:' system("cat > #{output_file}") end |
#all ⇒ Object
48 49 50 51 52 |
# File 'lib/clicoder/cli.rb', line 48 def all invoke :build invoke :execute invoke :judge end |
#browse ⇒ Object
137 138 139 140 141 |
# File 'lib/clicoder/cli.rb', line 137 def browse load_local_config site = get_site Launchy.open(site.problem_url) end |
#build ⇒ Object
55 56 57 58 |
# File 'lib/clicoder/cli.rb', line 55 def build load_local_config system('make build') end |
#download ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/clicoder/cli.rb', line 125 def download load_local_config site = get_site # TODO: this is not beautiful Dir.chdir('..') do site.download_description site.download_inputs site.download_outputs end end |
#execute ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/clicoder/cli.rb', line 61 def execute load_local_config Dir.glob("#{INPUTS_DIRNAME}/*.txt").each do |input| puts "executing #{input}" FileUtils.cp(input, TEMP_INPUT_FILENAME) system("make execute") FileUtils.cp(TEMP_OUTPUT_FILENAME, "#{MY_OUTPUTS_DIRNAME}/#{File.basename(input)}") end FileUtils.rm([TEMP_INPUT_FILENAME, TEMP_OUTPUT_FILENAME]) end |
#judge ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/clicoder/cli.rb', line 74 def judge load_local_config accepted = true judge = Judge.new() Dir.glob("#{OUTPUTS_DIRNAME}/*.txt").each do |output| puts "judging #{output}" my_output = "#{MY_OUTPUTS_DIRNAME}/#{File.basename(output)}" if File.exists?(my_output) unless judge.judge(output, my_output) puts '! Wrong Answer' system("diff -y #{output} #{my_output}") accepted = false end else puts "! #{my_output} does not exist" accepted = false end end if accepted puts "Correct Answer" else puts "Wrong Answer" end end |
#submit ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/clicoder/cli.rb', line 100 def submit load_local_config site = get_site if site.submit puts "Submission Succeeded." site.open_submission else puts "Submission Failed." exit 1 end end |