class AtCoderVcFriends::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_vc_friends/cli.rb, line 115 def check_and_go vf = ctx.verifier if ctx.sample_test_runner.test_all # submit automatically ctx.scraping_agent.submit vf.unverify else # enable manual submit vf.verify end end
exec_command(command, path, *args)
click to toggle source
# File lib/at_coder_vc_friends/cli.rb, line 67 def exec_command(command, path, *args) @ctx = Context.new(@options, path) case command when 'setup' setup(*args) when 'test-one' test_one(*args) when 'test-all' test_all when 'submit' submit when 'check-and-go' check_and_go else raise AtCoderFriends::ParamError, "unknown command: #{command}" end ctx.post_process end
handle_exiting_option()
click to toggle source
# File lib/at_coder_vc_friends/cli.rb, line 60 def handle_exiting_option return unless EXITING_OPTIONS.any? { |o| @options.key? o } puts AtCoderFriends::VERSION if @options[:version] exit STATUS_SUCCESS end
parse_options!(args)
click to toggle source
# File lib/at_coder_vc_friends/cli.rb, line 43 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 AtCoderFriends::ParamError, e.message end
run(args = ARGV)
click to toggle source
# File lib/at_coder_vc_friends/cli.rb, line 25 def run(args = ARGV) parse_options!(args) handle_exiting_option raise AtCoderFriends::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(url)
click to toggle source
# File lib/at_coder_vc_friends/cli.rb, line 86 def setup(url) path = ctx.path raise AtCoderFriends::AppError, "#{path} is not empty." \ if Dir.exist?(path) && !Dir["#{path}/*"].empty? ctx.scraping_agent.fetch_all_vc(url) do |pbm| AtCoderFriends::Parser::Main.process(pbm) ctx.generator.process(pbm) ctx.emitter.emit(pbm) end end
submit()
click to toggle source
# File lib/at_coder_vc_friends/cli.rb, line 107 def submit vf = ctx.verifier raise AtCoderFriends::AppError, "#{vf.file} has not been tested." unless vf.verified? ctx.scraping_agent.submit vf.unverify end
test_all()
click to toggle source
# File lib/at_coder_vc_friends/cli.rb, line 102 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_vc_friends/cli.rb, line 98 def test_one(id = '001') ctx.sample_test_runner.test_one(id) end