Class: AtCoderFriends::CLI
- Inherits:
-
Object
- Object
- AtCoderFriends::CLI
- Defined in:
- lib/at_coder_friends/cli.rb
Overview
command line interface
Constant Summary collapse
- EXITING_OPTIONS =
i[version].freeze
- OPTION_BANNER =
"Usage:\n at_coder_friends setup path/contest # setup contest folder\n at_coder_friends test-one path/contest/src # run 1st test case\n at_coder_friends test-all path/contest/src # run all test cases\n at_coder_friends submit path/contest/src # submit source code\n at_coder_friends check-and-go path/contest/src # submit source if all tests passed\n at_coder_friends open-contest path/contest/src # open contest page\nOptions:\n"
- STATUS_SUCCESS =
0
- STATUS_ERROR =
1
Instance Attribute Summary collapse
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
Instance Method Summary collapse
- #command_check_and_go ⇒ Object
- #command_judge_all ⇒ Object
- #command_judge_one(id = '') ⇒ Object
- #command_open_contest ⇒ Object
- #command_setup ⇒ Object
- #command_submit ⇒ Object
- #command_test_all ⇒ Object
- #command_test_one(id = '001') ⇒ Object
- #exec_command(command, path, *args) ⇒ Object
- #handle_exiting_option ⇒ Object
- #open_submission_list ⇒ Object
- #parse_options!(args) ⇒ Object
- #run(args = ARGV) ⇒ Object
Instance Attribute Details
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
24 25 26 |
# File 'lib/at_coder_friends/cli.rb', line 24 def ctx @ctx end |
Instance Method Details
#command_check_and_go ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/at_coder_friends/cli.rb', line 108 def command_check_and_go vf = ctx.verifier if ctx.sample_test_runner.test_all # submit automatically ctx.scraping_agent.submit vf.unverify open_submission_list else # enable manual submit vf.verify end end |
#command_judge_all ⇒ Object
125 126 127 |
# File 'lib/at_coder_friends/cli.rb', line 125 def command_judge_all ctx.judge_test_runner.judge_all end |
#command_judge_one(id = '') ⇒ Object
121 122 123 |
# File 'lib/at_coder_friends/cli.rb', line 121 def command_judge_one(id = '') ctx.judge_test_runner.judge_one(id) end |
#command_open_contest ⇒ Object
129 130 131 |
# File 'lib/at_coder_friends/cli.rb', line 129 def command_open_contest Launchy.open(ctx.scraping_agent.contest_url) end |
#command_setup ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/at_coder_friends/cli.rb', line 78 def command_setup path = ctx.path raise AppError, "#{path} is not empty." \ if Dir.exist?(path) && !Dir["#{path}/*"].empty? ctx.scraping_agent.fetch_all do |pbm| Parser::Main.process(pbm) ctx.generator.process(pbm) ctx.emitter.emit(pbm) end end |
#command_submit ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/at_coder_friends/cli.rb', line 99 def command_submit vf = ctx.verifier raise AppError, "#{vf.file} has not been tested." unless vf.verified? ctx.scraping_agent.submit vf.unverify open_submission_list end |
#command_test_all ⇒ Object
94 95 96 97 |
# File 'lib/at_coder_friends/cli.rb', line 94 def command_test_all ctx.sample_test_runner.test_all ctx.verifier.verify end |
#command_test_one(id = '001') ⇒ Object
90 91 92 |
# File 'lib/at_coder_friends/cli.rb', line 90 def command_test_one(id = '001') ctx.sample_test_runner.test_one(id) end |
#exec_command(command, path, *args) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/at_coder_friends/cli.rb', line 68 def exec_command(command, path, *args) @ctx = Context.new(, path) mtd = "command_#{command.gsub('-', '_')}" raise ParamError, "unknown command: #{command}" unless respond_to?(mtd) send(mtd, *args) ctx.post_process end |
#handle_exiting_option ⇒ Object
61 62 63 64 65 66 |
# File 'lib/at_coder_friends/cli.rb', line 61 def handle_exiting_option return unless EXITING_OPTIONS.any? { |o| .key? o } puts AtCoderFriends::VERSION if [:version] exit STATUS_SUCCESS end |
#open_submission_list ⇒ Object
133 134 135 136 137 |
# File 'lib/at_coder_friends/cli.rb', line 133 def open_submission_list url = ctx.scraping_agent.contest_url('submissions/me') puts "submission status : #{url}" Launchy.open(url) end |
#parse_options!(args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/at_coder_friends/cli.rb', line 44 def (args) op = OptionParser.new do |opts| opts. = OPTION_BANNER opts.on('-v', '--version', 'Display version.') do [:version] = true end opts.on('-d', '--debug', 'Display debug info.') do [:debug] = true end end @usage = op.to_s = {} op.parse!(args) rescue OptionParser::InvalidOption => e raise ParamError, e. end |
#run(args = ARGV) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/at_coder_friends/cli.rb', line 26 def run(args = ARGV) (args) handle_exiting_option raise ParamError, 'command or path is not specified.' if args.size < 2 exec_command(*args) STATUS_SUCCESS rescue AtCoderFriends::ParamError => e warn @usage warn "error: #{e.message}" STATUS_ERROR rescue AtCoderFriends::AppError => e warn e. STATUS_ERROR rescue SystemExit => e e.status end |