class AtcoderTools::CLI
Constants
- Prompt
Public Instance Methods
create(contest_name)
click to toggle source
# File lib/atcoder_tools/cli.rb, line 80 def create(contest_name) contest = Contest.new(contest_name) contest.check_validity! contest.create! log_info 'successfully created' end
delete(contest_name=nil)
click to toggle source
# File lib/atcoder_tools/cli.rb, line 143 def delete(contest_name=nil) unless contest_name contest_name = Prompt.select("Choose your submit contest?") do |submit| Contest.list.each_with_index do |contest, i| submit.choice contest.name if Settings.new.current_contest&.name == contest.name submit.default i + 1 end end end end FileUtils.rm_rf(contest_name) FileUtils.rm_rf(".atcoder/#{contest_name}") puts 'successfully deleted' end
language(lang='')
click to toggle source
# File lib/atcoder_tools/cli.rb, line 54 def language(lang='') unless ['ruby', 'c++(gcc)'].include?(lang) lang = Prompt.select("choose your default language.", ['ruby', 'c++(gcc)']) end # コマンドが通っているかテスト log_info "Checking path ..." res = case lang when 'ruby' !!system('ruby -v') when 'c++(gcc)' !!system('c++ -v') end unless res raise "Cannot find path of #{lang}. Is `$ #{lang} -v` working?" end settings = Settings.new settings.language = lang settings.save! puts log_info 'Default language successfully changed!' end
login()
click to toggle source
# File lib/atcoder_tools/cli.rb, line 18 def login # 認証情報を書き込むので、gitignoreを設定する unless Dir.exist?('.atcoder') Dir.mkdir('.atcoder') end File.open(".atcoder/.gitignore", mode = "w"){|f| f.write("*") # ファイルに書き込む } loop do prompt = TTY::Prompt.new username = prompt.ask("What is your atcoder username?", required: true) password = prompt.mask("What is your atcoder password?", required: true) puts "" log_info 'starting test login.' if Atcoder.test_login(username, password) settings = Settings.new settings.username = username settings.password = password settings.save! log_info 'OK!' break else log_error "Your username or password is invalid! try again!" end end end
logout()
click to toggle source
# File lib/atcoder_tools/cli.rb, line 47 def logout settings = Settings.new settings.destroy_credentials! settings.save! end
start()
click to toggle source
# File lib/atcoder_tools/cli.rb, line 89 def start listener = Listen.to('.', ignore: /.atcoder\/.*/) do |modified, added, removed| if modified[0] contest_name ,task_name = modified[0].split('/')[-2..-1] task_name = task_name.scan(/(.*)\..*/)[0][0] contest = Contest.new(contest_name) # thor と名前空間がかぶっているため task = ::Task.new(contest, task_name) # 最後に動かしたcontest, taskを記憶 settings = Settings.new settings.current_contest = contest settings.current_task = task settings.save! task.run end end log_info 'started actoder_tools session.' listener.start sleep end
submit()
click to toggle source
# File lib/atcoder_tools/cli.rb, line 113 def submit prompt = TTY::Prompt.new # contest_name = prompt.select("Choose your submit contest?", Contest.list.map(&:name)) contest_name = Prompt.select("Choose your submit contest?") do |submit| Contest.list.each_with_index do |contest, i| submit.choice contest.name if Settings.new.current_contest&.name == contest.name submit.default i + 1 end end end # contestによっては6種類ない可能性がある。 task_list = ['a', 'b', 'c', 'd', 'e', 'f'] task_name = prompt.select("Choose your tesk?") do |submit| task_list.each_with_index do |task, i| submit.choice task if Settings.new.current_task&.name == task submit.default i + 1 end end end contest = Contest.new(contest_name) # thor と名前空間がかぶっているため task = ::Task.new(contest, task_name) Atcoder.submit(task) end