Class: AtCoderVcFriends::CLI
- Inherits:
-
Object
- Object
- AtCoderVcFriends::CLI
- Defined in:
- lib/at_coder_vc_friends/cli.rb
Overview
command line interface
Constant Summary collapse
- EXITING_OPTIONS =
i[version].freeze
- OPTION_BANNER =
"Usage:\n at_coder_vc_friends setup path/to/contest url # setup contest folder\n at_coder_vc_friends test-one path/to/src # run 1st test case\n at_coder_vc_friends test-all path/to/src # run all test cases\n at_coder_vc_friends submit path/to/src # submit source code\n at_coder_vc_friends check-and-go path/to/src # submit source if all tests passed\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
- #check_and_go ⇒ Object
- #exec_command(command, path, *args) ⇒ Object
- #handle_exiting_option ⇒ Object
- #parse_options!(args) ⇒ Object
- #run(args = ARGV) ⇒ Object
- #setup(url) ⇒ Object
- #submit ⇒ Object
- #test_all ⇒ Object
- #test_one(id = '001') ⇒ Object
Instance Attribute Details
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
23 24 25 |
# File 'lib/at_coder_vc_friends/cli.rb', line 23 def ctx @ctx end |
Instance Method Details
#check_and_go ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# 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) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/at_coder_vc_friends/cli.rb', line 67 def exec_command(command, path, *args) @ctx = Context.new(, 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 ⇒ Object
60 61 62 63 64 65 |
# File 'lib/at_coder_vc_friends/cli.rb', line 60 def handle_exiting_option return unless EXITING_OPTIONS.any? { |o| .key? o } puts AtCoderFriends::VERSION if [:version] exit STATUS_SUCCESS end |
#parse_options!(args) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/at_coder_vc_friends/cli.rb', line 43 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 AtCoderFriends::ParamError, e. end |
#run(args = ARGV) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/at_coder_vc_friends/cli.rb', line 25 def run(args = ARGV) (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. STATUS_ERROR rescue SystemExit => e e.status end |
#setup(url) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# 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 ⇒ Object
107 108 109 110 111 112 113 |
# 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 ⇒ Object
102 103 104 105 |
# 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') ⇒ Object
98 99 100 |
# File 'lib/at_coder_vc_friends/cli.rb', line 98 def test_one(id = '001') ctx.sample_test_runner.test_one(id) end |