class AtCoderFriends::CLI
command line interface
Constants
- EXITING_OPTIONS
- OPTION_BANNER
- STATUS_ERROR
- STATUS_SUCCESS
Attributes
ctx[R]
Public Instance Methods
check_and_go()
click to toggle source
# File lib/at_coder_friends/cli.rb, line 123 def 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
exec_command(command, path, *args)
click to toggle source
# File lib/at_coder_friends/cli.rb, line 68 def exec_command(command, path, *args) @ctx = Context.new(@options, path) case command when 'setup' setup when 'test-one' test_one(*args) when 'test-all' test_all when 'submit' submit when 'check-and-go' check_and_go when 'judge-one' judge_one(*args) when 'judge-all' judge_all when 'open-contest' open_contest else raise ParamError, "unknown command: #{command}" end ctx.post_process end
handle_exiting_option()
click to toggle source
# File lib/at_coder_friends/cli.rb, line 61 def handle_exiting_option return unless EXITING_OPTIONS.any? { |o| @options.key? o } puts AtCoderFriends::VERSION if @options[:version] exit STATUS_SUCCESS end
judge_all()
click to toggle source
# File lib/at_coder_friends/cli.rb, line 140 def judge_all ctx.judge_test_runner.judge_all end
judge_one(id = '')
click to toggle source
# File lib/at_coder_friends/cli.rb, line 136 def judge_one(id = '') ctx.judge_test_runner.judge_one(id) end
open_contest()
click to toggle source
# File lib/at_coder_friends/cli.rb, line 144 def open_contest Launchy.open(ctx.scraping_agent.contest_url) end
open_submission_list()
click to toggle source
# File lib/at_coder_friends/cli.rb, line 148 def open_submission_list url = ctx.scraping_agent.contest_url('submissions/me') puts "submission status : #{url}" Launchy.open(url) end
parse_options!(args)
click to toggle source
# File lib/at_coder_friends/cli.rb, line 44 def parse_options!(args) op = OptionParser.new do |opts| opts.banner = OPTION_BANNER opts.on('-v', '--version', 'Display version.') do @options[:version] = true end opts.on('-d', '--debug', 'Display debug info.') do @options[:debug] = true end end @usage = op.to_s @options = {} op.parse!(args) rescue OptionParser::InvalidOption => e raise ParamError, e.message end
run(args = ARGV)
click to toggle source
# File lib/at_coder_friends/cli.rb, line 26 def run(args = ARGV) parse_options!(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.message STATUS_ERROR rescue SystemExit => e e.status end
setup()
click to toggle source
# File lib/at_coder_friends/cli.rb, line 93 def 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
submit()
click to toggle source
# File lib/at_coder_friends/cli.rb, line 114 def 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
test_all()
click to toggle source
# File lib/at_coder_friends/cli.rb, line 109 def test_all ctx.sample_test_runner.test_all ctx.verifier.verify end
test_one(id = '001')
click to toggle source
# File lib/at_coder_friends/cli.rb, line 105 def test_one(id = '001') ctx.sample_test_runner.test_one(id) end