Class: AtCoderFriends::CLI
- Inherits:
-
Object
- Object
- AtCoderFriends::CLI
show all
- Includes:
- PathUtil
- Defined in:
- lib/at_coder_friends/cli.rb
Overview
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\nOptions:\n"
- STATUS_SUCCESS =
0
- STATUS_ERROR =
1
Constants included
from PathUtil
PathUtil::CASES_DIR, PathUtil::SMP_DIR
Instance Method Summary
collapse
Methods included from PathUtil
cases_dir, contest_name, smp_dir, split_prg_path
Instance Method Details
#exec_command(command, path, id = nil) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/at_coder_friends/cli.rb', line 61
def exec_command(command, path, id = nil)
case command
when 'setup'
setup(path)
when 'test-one'
test_one(path, id)
when 'test-all'
test_all(path)
when 'submit'
submit(path)
when 'judge-one'
judge_one(path, id)
when 'judge-all'
judge_all(path)
else
raise ParamError, "unknown command: #{command}"
end
end
|
#handle_exiting_option ⇒ Object
55
56
57
58
59
|
# File 'lib/at_coder_friends/cli.rb', line 55
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(path) ⇒ Object
118
119
120
|
# File 'lib/at_coder_friends/cli.rb', line 118
def judge_all(path)
JudgeTestRunner.new(path).judge_all
end
|
#judge_one(path, id) ⇒ Object
113
114
115
116
|
# File 'lib/at_coder_friends/cli.rb', line 113
def judge_one(path, id)
id ||= ''
JudgeTestRunner.new(path).judge_one(id)
end
|
#parse_options!(args) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/at_coder_friends/cli.rb', line 41
def parse_options!(args)
op = OptionParser.new do |opts|
opts.banner = OPTION_BANNER
opts.on('-v', '--version', 'Display version.') do
@options[:version] = true
end
end
@usage = op.to_s
@options = {}
op.parse!(args)
rescue OptionParser::InvalidOption => e
raise ParamError, e.message
end
|
#run(args = ARGV) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/at_coder_friends/cli.rb', line 23
def run(args = ARGV)
parse_options!(args)
handle_exiting_option
raise ParamError, 'command or path is not specified.' if args.size < 2
@config = ConfigLoader.load_config(args[1])
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(path) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/at_coder_friends/cli.rb', line 80
def setup(path)
raise AppError, "#{path} is not empty." \
if Dir.exist?(path) && !Dir["#{path}/*"].empty?
agent = ScrapingAgent.new(contest_name(path), @config)
parser = FormatParser.new
rb_gen = RubyGenerator.new
cxx_gen = CxxGenerator.new
emitter = Emitter.new(path)
agent.fetch_all do |pbm|
parser.process(pbm)
rb_gen.process(pbm)
cxx_gen.process(pbm)
emitter.emit(pbm)
end
end
|
#submit(path) ⇒ Object
106
107
108
109
110
111
|
# File 'lib/at_coder_friends/cli.rb', line 106
def submit(path)
vf = Verifier.new(path)
raise AppError, "#{vf.file} has not been tested." unless vf.verified?
ScrapingAgent.new(contest_name(path), @config).submit(path)
vf.unverify
end
|
#test_all(path) ⇒ Object
101
102
103
104
|
# File 'lib/at_coder_friends/cli.rb', line 101
def test_all(path)
SampleTestRunner.new(path).test_all
Verifier.new(path).verify
end
|
#test_one(path, id) ⇒ Object
96
97
98
99
|
# File 'lib/at_coder_friends/cli.rb', line 96
def test_one(path, id)
id ||= 1
SampleTestRunner.new(path).test_one(id)
end
|